SCsub 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. #!/usr/bin/env python
  2. Import("env")
  3. Import("env_modules")
  4. # Thirdparty sources
  5. libvpx_dir = "#thirdparty/libvpx/"
  6. libvpx_sources = [
  7. "vp8/vp8_dx_iface.c",
  8. "vp8/common/generic/systemdependent.c",
  9. "vp8/common/alloccommon.c",
  10. "vp8/common/blockd.c",
  11. "vp8/common/copy_c.c",
  12. "vp8/common/debugmodes.c",
  13. "vp8/common/dequantize.c",
  14. "vp8/common/entropy.c",
  15. "vp8/common/entropymode.c",
  16. "vp8/common/entropymv.c",
  17. "vp8/common/extend.c",
  18. "vp8/common/filter.c",
  19. "vp8/common/findnearmv.c",
  20. "vp8/common/idct_blk.c",
  21. "vp8/common/idctllm.c",
  22. "vp8/common/loopfilter_filters.c",
  23. "vp8/common/mbpitch.c",
  24. "vp8/common/modecont.c",
  25. "vp8/common/quant_common.c",
  26. "vp8/common/reconinter.c",
  27. "vp8/common/reconintra.c",
  28. "vp8/common/reconintra4x4.c",
  29. "vp8/common/rtcd.c",
  30. "vp8/common/setupintrarecon.c",
  31. "vp8/common/swapyv12buffer.c",
  32. "vp8/common/treecoder.c",
  33. "vp8/common/vp8_loopfilter.c",
  34. "vp8/decoder/dboolhuff.c",
  35. "vp8/decoder/decodeframe.c",
  36. "vp8/decoder/decodemv.c",
  37. "vp8/decoder/detokenize.c",
  38. "vp8/decoder/onyxd_if.c",
  39. "vp9/vp9_dx_iface.c",
  40. "vp9/common/vp9_alloccommon.c",
  41. "vp9/common/vp9_blockd.c",
  42. "vp9/common/vp9_common_data.c",
  43. "vp9/common/vp9_debugmodes.c",
  44. "vp9/common/vp9_entropy.c",
  45. "vp9/common/vp9_entropymode.c",
  46. "vp9/common/vp9_entropymv.c",
  47. "vp9/common/vp9_filter.c",
  48. "vp9/common/vp9_frame_buffers.c",
  49. "vp9/common/vp9_idct.c",
  50. "vp9/common/vp9_loopfilter.c",
  51. "vp9/common/vp9_mvref_common.c",
  52. "vp9/common/vp9_pred_common.c",
  53. "vp9/common/vp9_quant_common.c",
  54. "vp9/common/vp9_reconinter.c",
  55. "vp9/common/vp9_reconintra.c",
  56. "vp9/common/vp9_rtcd.c",
  57. "vp9/common/vp9_scale.c",
  58. "vp9/common/vp9_scan.c",
  59. "vp9/common/vp9_seg_common.c",
  60. "vp9/common/vp9_thread_common.c",
  61. "vp9/common/vp9_tile_common.c",
  62. "vp9/decoder/vp9_decodeframe.c",
  63. "vp9/decoder/vp9_decodemv.c",
  64. "vp9/decoder/vp9_decoder.c",
  65. "vp9/decoder/vp9_detokenize.c",
  66. "vp9/decoder/vp9_dsubexp.c",
  67. "vp9/decoder/vp9_dthread.c",
  68. "vpx/src/vpx_codec.c",
  69. "vpx/src/vpx_decoder.c",
  70. "vpx/src/vpx_image.c",
  71. "vpx/src/vpx_psnr.c",
  72. "vpx_dsp/bitreader.c",
  73. "vpx_dsp/bitreader_buffer.c",
  74. "vpx_dsp/intrapred.c",
  75. "vpx_dsp/inv_txfm.c",
  76. "vpx_dsp/loopfilter.c",
  77. "vpx_dsp/prob.c",
  78. "vpx_dsp/vpx_convolve.c",
  79. "vpx_dsp/vpx_dsp_rtcd.c",
  80. "vpx_mem/vpx_mem.c",
  81. "vpx_scale/vpx_scale_rtcd.c",
  82. "vpx_scale/generic/yv12config.c",
  83. "vpx_scale/generic/yv12extend.c",
  84. "vpx_util/vpx_thread.c",
  85. ]
  86. libvpx_sources_mt = [
  87. "vp8/decoder/threading.c",
  88. ]
  89. libvpx_sources_intrin_x86 = [
  90. "vp8/common/x86/filter_x86.c",
  91. "vp8/common/x86/loopfilter_x86.c",
  92. "vp8/common/x86/vp8_asm_stubs.c",
  93. "vpx_dsp/x86/vpx_asm_stubs.c",
  94. ]
  95. libvpx_sources_intrin_x86_mmx = [
  96. "vp8/common/x86/idct_blk_mmx.c",
  97. ]
  98. libvpx_sources_intrin_x86_sse2 = [
  99. "vp8/common/x86/idct_blk_sse2.c",
  100. "vp9/common/x86/vp9_idct_intrin_sse2.c",
  101. "vpx_dsp/x86/inv_txfm_sse2.c",
  102. "vpx_dsp/x86/loopfilter_sse2.c",
  103. ]
  104. libvpx_sources_intrin_x86_ssse3 = ["vpx_dsp/x86/vpx_subpixel_8t_intrin_ssse3.c"]
  105. libvpx_sources_intrin_x86_avx2 = ["vpx_dsp/x86/loopfilter_avx2.c", "vpx_dsp/x86/vpx_subpixel_8t_intrin_avx2.c"]
  106. libvpx_sources_x86asm = [
  107. "vp8/common/x86/copy_sse2.asm",
  108. "vp8/common/x86/copy_sse3.asm",
  109. "vp8/common/x86/dequantize_mmx.asm",
  110. "vp8/common/x86/idctllm_mmx.asm",
  111. "vp8/common/x86/idctllm_sse2.asm",
  112. "vp8/common/x86/iwalsh_mmx.asm",
  113. "vp8/common/x86/iwalsh_sse2.asm",
  114. "vp8/common/x86/loopfilter_sse2.asm",
  115. "vp8/common/x86/recon_mmx.asm",
  116. "vp8/common/x86/recon_sse2.asm",
  117. "vp8/common/x86/subpixel_mmx.asm",
  118. "vp8/common/x86/subpixel_sse2.asm",
  119. "vp8/common/x86/subpixel_ssse3.asm",
  120. "vp8/common/x86/vp8_loopfilter_mmx.asm",
  121. "vpx_dsp/x86/intrapred_sse2.asm",
  122. "vpx_dsp/x86/intrapred_ssse3.asm",
  123. "vpx_dsp/x86/inv_wht_sse2.asm",
  124. "vpx_dsp/x86/vpx_convolve_copy_sse2.asm",
  125. "vpx_dsp/x86/vpx_subpixel_8t_sse2.asm",
  126. "vpx_dsp/x86/vpx_subpixel_8t_ssse3.asm",
  127. "vpx_dsp/x86/vpx_subpixel_bilinear_sse2.asm",
  128. "vpx_dsp/x86/vpx_subpixel_bilinear_ssse3.asm",
  129. "vpx_ports/emms.asm",
  130. ]
  131. libvpx_sources_x86_64asm = ["vp8/common/x86/loopfilter_block_sse2_x86_64.asm", "vpx_dsp/x86/inv_txfm_ssse3_x86_64.asm"]
  132. libvpx_sources_arm = [
  133. "vpx_ports/arm_cpudetect.c",
  134. "vp8/common/arm/loopfilter_arm.c",
  135. ]
  136. libvpx_sources_arm_neon = [
  137. "vp8/common/arm/neon/bilinearpredict_neon.c",
  138. "vp8/common/arm/neon/copymem_neon.c",
  139. "vp8/common/arm/neon/dc_only_idct_add_neon.c",
  140. "vp8/common/arm/neon/dequant_idct_neon.c",
  141. "vp8/common/arm/neon/dequantizeb_neon.c",
  142. "vp8/common/arm/neon/idct_blk_neon.c",
  143. "vp8/common/arm/neon/idct_dequant_0_2x_neon.c",
  144. "vp8/common/arm/neon/idct_dequant_full_2x_neon.c",
  145. "vp8/common/arm/neon/iwalsh_neon.c",
  146. "vp8/common/arm/neon/loopfiltersimplehorizontaledge_neon.c",
  147. "vp8/common/arm/neon/loopfiltersimpleverticaledge_neon.c",
  148. "vp8/common/arm/neon/mbloopfilter_neon.c",
  149. "vp8/common/arm/neon/shortidct4x4llm_neon.c",
  150. "vp8/common/arm/neon/sixtappredict_neon.c",
  151. "vp8/common/arm/neon/vp8_loopfilter_neon.c",
  152. "vp9/common/arm/neon/vp9_iht4x4_add_neon.c",
  153. "vp9/common/arm/neon/vp9_iht8x8_add_neon.c",
  154. "vpx_dsp/arm/idct16x16_1_add_neon.c",
  155. "vpx_dsp/arm/idct16x16_add_neon.c",
  156. "vpx_dsp/arm/idct16x16_neon.c",
  157. "vpx_dsp/arm/idct32x32_1_add_neon.c",
  158. "vpx_dsp/arm/idct32x32_add_neon.c",
  159. "vpx_dsp/arm/idct4x4_1_add_neon.c",
  160. "vpx_dsp/arm/idct4x4_add_neon.c",
  161. "vpx_dsp/arm/idct8x8_1_add_neon.c",
  162. "vpx_dsp/arm/idct8x8_add_neon.c",
  163. "vpx_dsp/arm/intrapred_neon.c",
  164. "vpx_dsp/arm/loopfilter_16_neon.c",
  165. "vpx_dsp/arm/loopfilter_4_neon.c",
  166. "vpx_dsp/arm/loopfilter_8_neon.c",
  167. "vpx_dsp/arm/loopfilter_neon.c",
  168. "vpx_dsp/arm/vpx_convolve8_avg_neon.c",
  169. "vpx_dsp/arm/vpx_convolve8_neon.c",
  170. "vpx_dsp/arm/vpx_convolve_avg_neon.c",
  171. "vpx_dsp/arm/vpx_convolve_copy_neon.c",
  172. "vpx_dsp/arm/vpx_convolve_neon.c",
  173. ]
  174. libvpx_sources_arm_neon_gas = [
  175. "vpx_dsp/arm/gas/intrapred_neon_asm.s",
  176. "vpx_dsp/arm/gas/loopfilter_mb_neon.s",
  177. "vpx_dsp/arm/gas/save_reg_neon.s",
  178. ]
  179. libvpx_sources_arm_neon_armasm_ms = [
  180. "vpx_dsp/arm/armasm_ms/intrapred_neon_asm.asm",
  181. "vpx_dsp/arm/armasm_ms/loopfilter_mb_neon.asm",
  182. "vpx_dsp/arm/armasm_ms/save_reg_neon.asm",
  183. ]
  184. libvpx_sources_arm_neon_gas_apple = [
  185. "vpx_dsp/arm/gas_apple/intrapred_neon_asm.s",
  186. "vpx_dsp/arm/gas_apple/loopfilter_mb_neon.s",
  187. "vpx_dsp/arm/gas_apple/save_reg_neon.s",
  188. ]
  189. libvpx_sources = [libvpx_dir + file for file in libvpx_sources]
  190. libvpx_sources_mt = [libvpx_dir + file for file in libvpx_sources_mt]
  191. libvpx_sources_intrin_x86 = [libvpx_dir + file for file in libvpx_sources_intrin_x86]
  192. libvpx_sources_intrin_x86_mmx = [libvpx_dir + file for file in libvpx_sources_intrin_x86_mmx]
  193. libvpx_sources_intrin_x86_sse2 = [libvpx_dir + file for file in libvpx_sources_intrin_x86_sse2]
  194. libvpx_sources_intrin_x86_ssse3 = [libvpx_dir + file for file in libvpx_sources_intrin_x86_ssse3]
  195. libvpx_sources_intrin_x86_avx2 = [libvpx_dir + file for file in libvpx_sources_intrin_x86_avx2]
  196. libvpx_sources_x86asm = [libvpx_dir + file for file in libvpx_sources_x86asm]
  197. libvpx_sources_x86_64asm = [libvpx_dir + file for file in libvpx_sources_x86_64asm]
  198. libvpx_sources_arm = [libvpx_dir + file for file in libvpx_sources_arm]
  199. libvpx_sources_arm_neon = [libvpx_dir + file for file in libvpx_sources_arm_neon]
  200. libvpx_sources_arm_neon_gas = [libvpx_dir + file for file in libvpx_sources_arm_neon_gas]
  201. libvpx_sources_arm_neon_armasm_ms = [libvpx_dir + file for file in libvpx_sources_arm_neon_armasm_ms]
  202. libvpx_sources_arm_neon_gas_apple = [libvpx_dir + file for file in libvpx_sources_arm_neon_gas_apple]
  203. env_libvpx = env_modules.Clone()
  204. env_libvpx.disable_warnings()
  205. env_libvpx.Prepend(CPPPATH=[libvpx_dir])
  206. webm_multithread = env["platform"] != "javascript"
  207. cpu_bits = env["bits"]
  208. webm_cpu_x86 = False
  209. webm_cpu_arm = False
  210. if env["platform"] == "uwp":
  211. if "arm" in env["PROGSUFFIX"]:
  212. webm_cpu_arm = True
  213. else:
  214. webm_cpu_x86 = True
  215. elif env["platform"] != "windows": # Disable for Windows, yasm SIMD optimizations trigger crash (GH-50862).
  216. import platform
  217. is_x11_or_server_arm = (env["platform"] == "x11" or env["platform"] == "server") and (
  218. platform.machine().startswith("arm") or platform.machine().startswith("aarch")
  219. )
  220. is_macos_x86 = env["platform"] == "osx" and ("arch" in env and (env["arch"] != "arm64"))
  221. is_ios_x86 = env["platform"] == "iphone" and ("arch" in env and env["arch"].startswith("x86"))
  222. is_android_x86 = env["platform"] == "android" and env["android_arch"].startswith("x86")
  223. if is_android_x86:
  224. cpu_bits = "32" if env["android_arch"] == "x86" else "64"
  225. webm_cpu_x86 = (
  226. not is_x11_or_server_arm
  227. and (cpu_bits == "32" or cpu_bits == "64")
  228. and (
  229. env["platform"] == "windows"
  230. or env["platform"] == "x11"
  231. or env["platform"] == "haiku"
  232. or is_macos_x86
  233. or is_android_x86
  234. or is_ios_x86
  235. )
  236. )
  237. webm_cpu_arm = (
  238. is_x11_or_server_arm
  239. or (not is_macos_x86 and env["platform"] == "osx")
  240. or (not is_ios_x86 and env["platform"] == "iphone")
  241. or (not is_android_x86 and env["platform"] == "android")
  242. )
  243. if webm_cpu_x86:
  244. import subprocess
  245. import os
  246. yasm_paths = [
  247. "yasm",
  248. "../../../yasm",
  249. ]
  250. yasm_found = False
  251. devnull = open(os.devnull)
  252. for yasm_path in yasm_paths:
  253. try:
  254. yasm_found = True
  255. subprocess.Popen([yasm_path, "--version"], stdout=devnull, stderr=devnull).communicate()
  256. except Exception:
  257. yasm_found = False
  258. if yasm_found:
  259. break
  260. if not yasm_found:
  261. webm_cpu_x86 = False
  262. print("YASM is necessary for WebM SIMD optimizations.")
  263. webm_simd_optimizations = False
  264. if webm_cpu_x86:
  265. if env["platform"] == "windows" or env["platform"] == "uwp":
  266. env_libvpx["ASFORMAT"] = "win"
  267. elif env["platform"] == "osx" or env["platform"] == "iphone":
  268. env_libvpx["ASFORMAT"] = "macho"
  269. else:
  270. env_libvpx["ASFORMAT"] = "elf"
  271. env_libvpx["ASFORMAT"] += cpu_bits
  272. env_libvpx["AS"] = "yasm"
  273. env_libvpx["ASFLAGS"] = "-I" + libvpx_dir[1:] + " -f $ASFORMAT -D $ASCPU"
  274. env_libvpx["ASCOM"] = "$AS $ASFLAGS -o $TARGET $SOURCES"
  275. if cpu_bits == "32":
  276. env_libvpx["ASCPU"] = "X86_32"
  277. elif cpu_bits == "64":
  278. env_libvpx["ASCPU"] = "X86_64"
  279. env_libvpx.Append(CPPDEFINES=["WEBM_X86ASM"])
  280. webm_simd_optimizations = True
  281. if webm_cpu_arm:
  282. if env["platform"] == "iphone":
  283. env_libvpx["ASFLAGS"] = "-arch armv7"
  284. elif (
  285. env["platform"] == "android"
  286. and env["android_arch"] == "armv7"
  287. or env["platform"] == "x11"
  288. or env["platform"] == "server"
  289. ):
  290. env_libvpx["ASFLAGS"] = "-mfpu=neon"
  291. elif env["platform"] == "uwp":
  292. env_libvpx["AS"] = "armasm"
  293. env_libvpx["ASFLAGS"] = ""
  294. env_libvpx["ASCOM"] = "$AS $ASFLAGS -o $TARGET $SOURCES"
  295. env_libvpx.Append(CPPDEFINES=["WEBM_ARMASM"])
  296. webm_simd_optimizations = True
  297. if webm_simd_optimizations == False and env["platform"] != "windows":
  298. print("WebM SIMD optimizations are disabled. Check if your CPU architecture, CPU bits or platform are supported!")
  299. env_libvpx.add_source_files(env.modules_sources, libvpx_sources)
  300. if webm_multithread:
  301. env_libvpx.add_source_files(env.modules_sources, libvpx_sources_mt)
  302. if webm_cpu_x86:
  303. is_clang_or_gcc = (
  304. ("gcc" in os.path.basename(env["CC"])) or ("clang" in os.path.basename(env["CC"])) or ("osxcross" in env)
  305. )
  306. env_libvpx_mmx = env_libvpx.Clone()
  307. if cpu_bits == "32" and is_clang_or_gcc:
  308. env_libvpx_mmx.Append(CCFLAGS=["-mmmx"])
  309. env_libvpx_mmx.add_source_files(env.modules_sources, libvpx_sources_intrin_x86_mmx)
  310. env_libvpx_sse2 = env_libvpx.Clone()
  311. if cpu_bits == "32" and is_clang_or_gcc:
  312. env_libvpx_sse2.Append(CCFLAGS=["-msse2"])
  313. env_libvpx_sse2.add_source_files(env.modules_sources, libvpx_sources_intrin_x86_sse2)
  314. env_libvpx_ssse3 = env_libvpx.Clone()
  315. if is_clang_or_gcc:
  316. env_libvpx_ssse3.Append(CCFLAGS=["-mssse3"])
  317. env_libvpx_ssse3.add_source_files(env.modules_sources, libvpx_sources_intrin_x86_ssse3)
  318. env_libvpx_avx2 = env_libvpx.Clone()
  319. if is_clang_or_gcc:
  320. env_libvpx_avx2.Append(CCFLAGS=["-mavx2"])
  321. env_libvpx_avx2.add_source_files(env.modules_sources, libvpx_sources_intrin_x86_avx2)
  322. env_libvpx.add_source_files(env.modules_sources, libvpx_sources_intrin_x86)
  323. env_libvpx.add_source_files(env.modules_sources, libvpx_sources_x86asm)
  324. if cpu_bits == "64":
  325. env_libvpx.add_source_files(env.modules_sources, libvpx_sources_x86_64asm)
  326. elif webm_cpu_arm:
  327. env_libvpx.add_source_files(env.modules_sources, libvpx_sources_arm)
  328. if env["platform"] == "android":
  329. env_libvpx.Prepend(CPPPATH=[libvpx_dir + "third_party/android"])
  330. env_libvpx.add_source_files(env.modules_sources, [libvpx_dir + "third_party/android/cpu-features.c"])
  331. env_libvpx_neon = env_libvpx.Clone()
  332. env_libvpx_neon.add_source_files(env.modules_sources, libvpx_sources_arm_neon)
  333. if env["platform"] == "uwp":
  334. env_libvpx.add_source_files(env.modules_sources, libvpx_sources_arm_neon_armasm_ms)
  335. elif env["platform"] == "iphone":
  336. env_libvpx.add_source_files(env.modules_sources, libvpx_sources_arm_neon_gas_apple)
  337. elif (is_x11_or_server_arm and cpu_bits == "32") or (
  338. env["platform"] == "android" and not env["android_arch"] == "arm64v8"
  339. ):
  340. env_libvpx.add_source_files(env.modules_sources, libvpx_sources_arm_neon_gas)