dillon - branch off of chromium-67.0.3396.87 and apply 67.bad-dfly
[chromium-dfly.git] / third_party / opus / BUILD.gn
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import("//build/config/arm.gni")
6 import("//testing/test.gni")
7
8 # If fixed point implementation shall be used (otherwise float).
9 use_opus_fixed_point = current_cpu == "arm" || current_cpu == "arm64"
10
11 # If ARM optimizations shall be used to accelerate performance.
12 # TODO(scottmg): Disabled on Fuchsia for now, see https://crbug.com/775272.
13 use_opus_arm_optimization =
14     current_cpu == "arm" || (current_cpu == "arm64" && is_ios)
15
16 # If OPUS Run Time CPU Detections (RTCD) shall be used.
17 # Based on the conditions in celt/arm/armcpu.c:
18 # defined(_MSC_VER) || defined(__linux__).
19 use_opus_rtcd = current_cpu == "arm" && (is_win || is_android || is_linux ||
20                                          is_bsd)
21
22 config("opus_config") {
23   include_dirs = [ "src/include" ]
24
25   if (use_opus_fixed_point) {
26     defines = [ "OPUS_FIXED_POINT" ]
27   }
28 }
29
30 config("opus_test_config") {
31   include_dirs = [
32     "src/celt",
33     "src/silk",
34   ]
35
36   if (is_win) {
37     defines = [ "inline=__inline" ]
38   }
39   if (is_android) {
40     libs = [ "log" ]
41   }
42   if (is_clang) {
43     cflags = [ "-Wno-absolute-value" ]
44   }
45 }
46
47 if (use_opus_rtcd) {
48   action("convert_rtcd_assembler") {
49     script = "convert_rtcd_assembler.py"
50     outputs = [
51       "$target_gen_dir/celt_pitch_xcorr_arm_gnu.S",
52     ]
53     args = [
54       rebase_path("//third_party/opus/src/celt/arm/arm2gnu.pl", root_build_dir),
55       rebase_path("//third_party/opus/src/celt/arm/celt_pitch_xcorr_arm.s",
56                   root_build_dir),
57       rebase_path("$target_gen_dir/celt_pitch_xcorr_arm_gnu.S", root_build_dir),
58     ]
59   }
60 }
61
62 static_library("opus") {
63   sources = [
64     "src/celt/_kiss_fft_guts.h",
65     "src/celt/arch.h",
66     "src/celt/bands.c",
67     "src/celt/bands.h",
68     "src/celt/celt.c",
69     "src/celt/celt.h",
70     "src/celt/celt_decoder.c",
71     "src/celt/celt_encoder.c",
72     "src/celt/celt_lpc.c",
73     "src/celt/celt_lpc.h",
74     "src/celt/cpu_support.h",
75     "src/celt/cwrs.c",
76     "src/celt/cwrs.h",
77     "src/celt/ecintrin.h",
78     "src/celt/entcode.c",
79     "src/celt/entcode.h",
80     "src/celt/entdec.c",
81     "src/celt/entdec.h",
82     "src/celt/entenc.c",
83     "src/celt/entenc.h",
84     "src/celt/fixed_debug.h",
85     "src/celt/fixed_generic.h",
86     "src/celt/float_cast.h",
87     "src/celt/kiss_fft.c",
88     "src/celt/kiss_fft.h",
89     "src/celt/laplace.c",
90     "src/celt/laplace.h",
91     "src/celt/mathops.c",
92     "src/celt/mathops.h",
93     "src/celt/mdct.c",
94     "src/celt/mdct.h",
95     "src/celt/mfrngcod.h",
96     "src/celt/modes.c",
97     "src/celt/modes.h",
98     "src/celt/os_support.h",
99     "src/celt/pitch.c",
100     "src/celt/pitch.h",
101     "src/celt/quant_bands.c",
102     "src/celt/quant_bands.h",
103     "src/celt/rate.c",
104     "src/celt/rate.h",
105     "src/celt/stack_alloc.h",
106     "src/celt/static_modes_fixed.h",
107     "src/celt/static_modes_float.h",
108     "src/celt/vq.c",
109     "src/celt/vq.h",
110     "src/include/opus.h",
111     "src/include/opus_custom.h",
112     "src/include/opus_defines.h",
113     "src/include/opus_multistream.h",
114     "src/include/opus_types.h",
115     "src/silk/A2NLSF.c",
116     "src/silk/API.h",
117     "src/silk/CNG.c",
118     "src/silk/HP_variable_cutoff.c",
119     "src/silk/Inlines.h",
120     "src/silk/LPC_analysis_filter.c",
121     "src/silk/LPC_fit.c",
122     "src/silk/LPC_inv_pred_gain.c",
123     "src/silk/LP_variable_cutoff.c",
124     "src/silk/MacroCount.h",
125     "src/silk/MacroDebug.h",
126     "src/silk/NLSF2A.c",
127     "src/silk/NLSF_VQ.c",
128     "src/silk/NLSF_VQ_weights_laroia.c",
129     "src/silk/NLSF_decode.c",
130     "src/silk/NLSF_del_dec_quant.c",
131     "src/silk/NLSF_encode.c",
132     "src/silk/NLSF_stabilize.c",
133     "src/silk/NLSF_unpack.c",
134     "src/silk/NSQ.c",
135     "src/silk/NSQ.h",
136     "src/silk/NSQ_del_dec.c",
137     "src/silk/PLC.c",
138     "src/silk/PLC.h",
139     "src/silk/SigProc_FIX.h",
140     "src/silk/VAD.c",
141     "src/silk/VQ_WMat_EC.c",
142     "src/silk/ana_filt_bank_1.c",
143     "src/silk/biquad_alt.c",
144     "src/silk/bwexpander.c",
145     "src/silk/bwexpander_32.c",
146     "src/silk/check_control_input.c",
147     "src/silk/code_signs.c",
148     "src/silk/control.h",
149     "src/silk/control_SNR.c",
150     "src/silk/control_audio_bandwidth.c",
151     "src/silk/control_codec.c",
152     "src/silk/debug.c",
153     "src/silk/debug.h",
154     "src/silk/dec_API.c",
155     "src/silk/decode_core.c",
156     "src/silk/decode_frame.c",
157     "src/silk/decode_indices.c",
158     "src/silk/decode_parameters.c",
159     "src/silk/decode_pitch.c",
160     "src/silk/decode_pulses.c",
161     "src/silk/decoder_set_fs.c",
162     "src/silk/define.h",
163     "src/silk/enc_API.c",
164     "src/silk/encode_indices.c",
165     "src/silk/encode_pulses.c",
166     "src/silk/errors.h",
167     "src/silk/gain_quant.c",
168     "src/silk/init_decoder.c",
169     "src/silk/init_encoder.c",
170     "src/silk/inner_prod_aligned.c",
171     "src/silk/interpolate.c",
172     "src/silk/lin2log.c",
173     "src/silk/log2lin.c",
174     "src/silk/macros.h",
175     "src/silk/main.h",
176     "src/silk/pitch_est_defines.h",
177     "src/silk/pitch_est_tables.c",
178     "src/silk/process_NLSFs.c",
179     "src/silk/quant_LTP_gains.c",
180     "src/silk/resampler.c",
181     "src/silk/resampler_down2.c",
182     "src/silk/resampler_down2_3.c",
183     "src/silk/resampler_private.h",
184     "src/silk/resampler_private_AR2.c",
185     "src/silk/resampler_private_IIR_FIR.c",
186     "src/silk/resampler_private_down_FIR.c",
187     "src/silk/resampler_private_up2_HQ.c",
188     "src/silk/resampler_rom.c",
189     "src/silk/resampler_rom.h",
190     "src/silk/resampler_structs.h",
191     "src/silk/shell_coder.c",
192     "src/silk/sigm_Q15.c",
193     "src/silk/sort.c",
194     "src/silk/stereo_LR_to_MS.c",
195     "src/silk/stereo_MS_to_LR.c",
196     "src/silk/stereo_decode_pred.c",
197     "src/silk/stereo_encode_pred.c",
198     "src/silk/stereo_find_predictor.c",
199     "src/silk/stereo_quant_pred.c",
200     "src/silk/structs.h",
201     "src/silk/sum_sqr_shift.c",
202     "src/silk/table_LSF_cos.c",
203     "src/silk/tables.h",
204     "src/silk/tables_LTP.c",
205     "src/silk/tables_NLSF_CB_NB_MB.c",
206     "src/silk/tables_NLSF_CB_WB.c",
207     "src/silk/tables_gain.c",
208     "src/silk/tables_other.c",
209     "src/silk/tables_pitch_lag.c",
210     "src/silk/tables_pulses_per_block.c",
211     "src/silk/tuning_parameters.h",
212     "src/silk/typedef.h",
213     "src/src/analysis.c",
214     "src/src/analysis.h",
215     "src/src/mlp.c",
216     "src/src/mlp.h",
217     "src/src/mlp_data.c",
218     "src/src/opus.c",
219     "src/src/opus_decoder.c",
220     "src/src/opus_encoder.c",
221     "src/src/opus_multistream.c",
222     "src/src/opus_multistream_decoder.c",
223     "src/src/opus_multistream_encoder.c",
224     "src/src/repacketizer.c",
225     "src/src/tansig_table.h",
226   ]
227
228   defines = [
229     "OPUS_BUILD",
230     "OPUS_EXPORT=",
231   ]
232
233   include_dirs = [
234     "src",
235     "src/celt",
236     "src/silk",
237   ]
238
239   configs -= [ "//build/config/compiler:chromium_code" ]
240   configs += [ "//build/config/compiler:no_chromium_code" ]
241   public_configs = [ ":opus_config" ]
242   cflags = []
243
244   if (is_win) {
245     defines += [
246       "USE_ALLOCA",
247       "inline=__inline",
248     ]
249
250     cflags += [
251       "/wd4305",  # Disable truncation warning in celt/pitch.c .
252       "/wd4334",  # Disable 32-bit shift warning in src/opus_encoder.c .
253     ]
254   } else {
255     defines += [
256       "HAVE_LRINT",
257       "HAVE_LRINTF",
258       "VAR_ARRAYS",
259     ]
260   }
261
262   if (is_debug) {
263     # Turn off a warning in opus_decoder.c when compiling without optimization.
264     defines += [ "OPUS_WILL_BE_SLOW" ]
265   }
266
267   if (!is_debug && (current_cpu == "arm" || current_cpu == "arm64")) {
268     configs -= [ "//build/config/compiler:default_optimization" ]
269
270     # TODO(crbug.com/621335) Rework this so that we don't have the confusion
271     # between "optimize_speed" and "optimize_max".
272     configs += [ "//build/config/compiler:optimize_speed" ]
273   }
274
275   if (use_opus_fixed_point) {
276     sources += [
277       "src/silk/fixed/LTP_analysis_filter_FIX.c",
278       "src/silk/fixed/LTP_scale_ctrl_FIX.c",
279       "src/silk/fixed/apply_sine_window_FIX.c",
280       "src/silk/fixed/autocorr_FIX.c",
281       "src/silk/fixed/burg_modified_FIX.c",
282       "src/silk/fixed/corrMatrix_FIX.c",
283       "src/silk/fixed/encode_frame_FIX.c",
284       "src/silk/fixed/find_LPC_FIX.c",
285       "src/silk/fixed/find_LTP_FIX.c",
286       "src/silk/fixed/find_pitch_lags_FIX.c",
287       "src/silk/fixed/find_pred_coefs_FIX.c",
288       "src/silk/fixed/k2a_FIX.c",
289       "src/silk/fixed/k2a_Q16_FIX.c",
290       "src/silk/fixed/main_FIX.h",
291       "src/silk/fixed/noise_shape_analysis_FIX.c",
292       "src/silk/fixed/pitch_analysis_core_FIX.c",
293       "src/silk/fixed/process_gains_FIX.c",
294       "src/silk/fixed/regularize_correlations_FIX.c",
295       "src/silk/fixed/residual_energy16_FIX.c",
296       "src/silk/fixed/residual_energy_FIX.c",
297       "src/silk/fixed/schur64_FIX.c",
298       "src/silk/fixed/schur_FIX.c",
299       "src/silk/fixed/structs_FIX.h",
300       "src/silk/fixed/vector_ops_FIX.c",
301       "src/silk/fixed/warped_autocorrelation_FIX.c",
302     ]
303
304     defines += [ "FIXED_POINT" ]
305
306     include_dirs += [ "src/silk/fixed" ]
307   } else {
308     sources += [
309       "src/silk/float/LPC_analysis_filter_FLP.c",
310       "src/silk/float/LPC_inv_pred_gain_FLP.c",
311       "src/silk/float/LTP_analysis_filter_FLP.c",
312       "src/silk/float/LTP_scale_ctrl_FLP.c",
313       "src/silk/float/SigProc_FLP.h",
314       "src/silk/float/apply_sine_window_FLP.c",
315       "src/silk/float/autocorrelation_FLP.c",
316       "src/silk/float/burg_modified_FLP.c",
317       "src/silk/float/bwexpander_FLP.c",
318       "src/silk/float/corrMatrix_FLP.c",
319       "src/silk/float/encode_frame_FLP.c",
320       "src/silk/float/energy_FLP.c",
321       "src/silk/float/find_LPC_FLP.c",
322       "src/silk/float/find_LTP_FLP.c",
323       "src/silk/float/find_pitch_lags_FLP.c",
324       "src/silk/float/find_pred_coefs_FLP.c",
325       "src/silk/float/inner_product_FLP.c",
326       "src/silk/float/k2a_FLP.c",
327       "src/silk/float/main_FLP.h",
328       "src/silk/float/noise_shape_analysis_FLP.c",
329       "src/silk/float/pitch_analysis_core_FLP.c",
330       "src/silk/float/process_gains_FLP.c",
331       "src/silk/float/regularize_correlations_FLP.c",
332       "src/silk/float/residual_energy_FLP.c",
333       "src/silk/float/scale_copy_vector_FLP.c",
334       "src/silk/float/scale_vector_FLP.c",
335       "src/silk/float/schur_FLP.c",
336       "src/silk/float/sort_FLP.c",
337       "src/silk/float/structs_FLP.h",
338       "src/silk/float/warped_autocorrelation_FLP.c",
339       "src/silk/float/wrappers_FLP.c",
340     ]
341
342     include_dirs += [ "src/silk/float" ]
343   }
344
345   if (use_opus_arm_optimization) {
346     sources += [
347       "src/celt/arm/fixed_arm64.h",
348       "src/celt/arm/fixed_armv4.h",
349       "src/celt/arm/fixed_armv5e.h",
350       "src/celt/arm/kiss_fft_armv4.h",
351       "src/celt/arm/kiss_fft_armv5e.h",
352       "src/celt/arm/pitch_arm.h",
353       "src/silk/arm/SigProc_FIX_armv4.h",
354       "src/silk/arm/SigProc_FIX_armv5e.h",
355       "src/silk/arm/macros_arm64.h",
356       "src/silk/arm/macros_armv4.h",
357       "src/silk/arm/macros_armv5e.h",
358     ]
359
360     if (current_cpu == "arm") {
361       defines += [
362         "OPUS_ARM_ASM",
363         "OPUS_ARM_INLINE_ASM",
364         "OPUS_ARM_INLINE_EDSP",
365       ]
366     }
367
368     if (use_opus_rtcd) {
369       sources += [
370         "$target_gen_dir/celt_pitch_xcorr_arm_gnu.S",
371         "src/celt/arm/arm_celt_map.c",
372         "src/celt/arm/armcpu.c",
373         "src/celt/arm/armcpu.h",
374         "src/celt/arm/fft_arm.h",
375         "src/celt/arm/mdct_arm.h",
376         "src/celt/arm/pitch_arm.h",
377         "src/silk/arm/arm_silk_map.c",
378       ]
379
380       defines += [
381         "OPUS_ARM_MAY_HAVE_EDSP",
382         "OPUS_ARM_MAY_HAVE_MEDIA",
383         "OPUS_HAVE_RTCD",
384       ]
385
386       deps = [
387         ":convert_rtcd_assembler",
388       ]
389     }
390
391     if (arm_use_neon) {
392       sources += [
393         "src/celt/arm/celt_neon_intr.c",
394         "src/celt/arm/pitch_neon_intr.c",
395         "src/silk/arm/LPC_inv_pred_gain_arm.h",
396         "src/silk/arm/LPC_inv_pred_gain_neon_intr.c",
397         "src/silk/arm/NSQ_del_dec_arm.h",
398         "src/silk/arm/NSQ_del_dec_neon_intr.c",
399         "src/silk/arm/NSQ_neon.c",
400         "src/silk/arm/NSQ_neon.h",
401         "src/silk/arm/biquad_alt_arm.h",
402         "src/silk/arm/biquad_alt_neon_intr.c",
403         "src/silk/fixed/arm/warped_autocorrelation_FIX_arm.h",
404         "src/silk/fixed/arm/warped_autocorrelation_FIX_neon_intr.c",
405       ]
406
407       defines += [
408         "OPUS_ARM_MAY_HAVE_NEON",
409         "OPUS_ARM_MAY_HAVE_NEON_INTR",
410       ]
411     }
412
413     if (is_ios && current_cpu == "arm64") {
414       # Runtime detection of CPU features not available on iOS.
415       defines += [
416         "OPUS_ARM_PRESUME_NEON_INTR",
417         "OPUS_ARM_PRESUME_AARCH64_NEON_INTR",
418       ]
419     }
420   }
421 }
422
423 executable("opus_compare") {
424   sources = [
425     "src/src/opus_compare.c",
426   ]
427
428   configs -= [ "//build/config/compiler:chromium_code" ]
429   configs += [
430     "//build/config/compiler:no_chromium_code",
431     ":opus_test_config",
432   ]
433
434   deps = [
435     ":opus",
436     "//build/config:exe_and_shlib_deps",
437     "//build/win:default_exe_manifest",
438   ]
439 }
440
441 executable("opus_demo") {
442   sources = [
443     "src/src/opus_demo.c",
444   ]
445
446   configs -= [ "//build/config/compiler:chromium_code" ]
447   configs += [
448     "//build/config/compiler:no_chromium_code",
449     ":opus_test_config",
450   ]
451
452   deps = [
453     ":opus",
454     "//build/config:exe_and_shlib_deps",
455     "//build/win:default_exe_manifest",
456   ]
457 }
458
459 test("test_opus_api") {
460   sources = [
461     "src/tests/test_opus_api.c",
462   ]
463
464   configs -= [ "//build/config/compiler:chromium_code" ]
465   configs += [
466     "//build/config/compiler:no_chromium_code",
467     ":opus_test_config",
468   ]
469
470   deps = [
471     ":opus",
472   ]
473 }
474
475 test("test_opus_encode") {
476   sources = [
477     "src/tests/opus_encode_regressions.c",
478     "src/tests/test_opus_encode.c",
479   ]
480
481   configs -= [ "//build/config/compiler:chromium_code" ]
482   configs += [
483     "//build/config/compiler:no_chromium_code",
484     ":opus_test_config",
485   ]
486
487   deps = [
488     ":opus",
489   ]
490 }
491
492 # GN orders flags on a target before flags from configs. The default config
493 # adds -Wall, and this flag have to be after -Wall -- so they need to
494 # come from a config and can't be on the target directly.
495 config("test_opus_decode_config") {
496   # test_opus_decode passes a null pointer to opus_decode() for an argument
497   # marked as requiring a non-null value by the nonnull function attribute,
498   # and expects opus_decode() to fail. Disable the -Wnonnull option to avoid
499   # a compilation error if -Werror is specified.
500   if (is_clang) {
501     cflags = [ "-Wno-nonnull" ]
502   }
503 }
504
505 test("test_opus_decode") {
506   sources = [
507     "src/tests/test_opus_decode.c",
508   ]
509
510   configs -= [ "//build/config/compiler:chromium_code" ]
511   configs += [
512     "//build/config/compiler:no_chromium_code",
513     ":opus_test_config",
514     ":test_opus_decode_config",
515   ]
516
517   deps = [
518     ":opus",
519   ]
520 }
521
522 test("test_opus_padding") {
523   sources = [
524     "src/tests/test_opus_padding.c",
525   ]
526
527   configs -= [ "//build/config/compiler:chromium_code" ]
528   configs += [
529     "//build/config/compiler:no_chromium_code",
530     ":opus_test_config",
531   ]
532
533   deps = [
534     ":opus",
535   ]
536 }