• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021, Alliance for Open Media. All rights reserved
2#
3# This source code is subject to the terms of the BSD 2 Clause License and
4# the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
5# was not distributed with this source code in the LICENSE file, you can
6# obtain it at www.aomedia.org/license/software. If the Alliance for Open
7# Media Patent License 1.0 was not distributed with this source code in the
8# PATENTS file, you can obtain it at www.aomedia.org/license/patent.
9#
10
11import os
12import sys
13
14
15def is_code_file(filename):
16  return filename.endswith(".c") or filename.endswith(".h")
17
18
19def is_simd_file(filename):
20  simd_keywords = [
21      "avx2", "sse2", "sse3", "ssse3", "sse4", "dspr2", "neon", "msa", "simd",
22      "x86"
23  ]
24  for keyword in simd_keywords:
25    if filename.find(keyword) >= 0:
26      return True
27  return False
28
29
30def get_code_file_list(path, exclude_file_set):
31  code_file_list = []
32  for cur_dir, sub_dir, file_list in os.walk(path):
33    for filename in file_list:
34      if is_code_file(filename) and not is_simd_file(
35          filename) and filename not in exclude_file_set:
36        file_path = os.path.join(cur_dir, filename)
37        code_file_list.append(file_path)
38  return code_file_list
39
40
41def av1_exclude_file_set():
42  exclude_file_set = {
43      "cfl_ppc.c",
44      "ppc_cpudetect.c",
45  }
46  return exclude_file_set
47
48
49def get_av1_pp_command(fake_header_dir, code_file_list):
50  pre_command = "gcc -w -nostdinc -E -I./ -I../ -I" + fake_header_dir + (" "
51                                                                         "-D'ATTRIBUTE_PACKED='"
52                                                                         " "
53                                                                         "-D'__attribute__(x)='"
54                                                                         " "
55                                                                         "-D'__inline__='"
56                                                                         " "
57                                                                         "-D'float_t=float'"
58                                                                         " "
59                                                                         "-D'DECLARE_ALIGNED(n,"
60                                                                         " typ,"
61                                                                         " "
62                                                                         "val)=typ"
63                                                                         " val'"
64                                                                         " "
65                                                                         "-D'volatile='"
66                                                                         " "
67                                                                         "-D'AV1_K_MEANS_DIM=2'"
68                                                                         " "
69                                                                         "-D'INLINE='"
70                                                                         " "
71                                                                         "-D'AOM_INLINE='"
72                                                                         " "
73                                                                         "-D'AOM_FORCE_INLINE='"
74                                                                         " "
75                                                                         "-D'inline='"
76                                                                         )
77  return pre_command + " " + " ".join(code_file_list)
78
79
80def modify_av1_rtcd(build_dir):
81  av1_rtcd = os.path.join(build_dir, "config/av1_rtcd.h")
82  fp = open(av1_rtcd)
83  string = fp.read()
84  fp.close()
85  new_string = string.replace("#ifdef RTCD_C", "#if 0")
86  fp = open(av1_rtcd, "w")
87  fp.write(new_string)
88  fp.close()
89
90
91def preprocess_av1(aom_dir, build_dir, fake_header_dir):
92  cur_dir = os.getcwd()
93  output = os.path.join(cur_dir, "av1_pp.c")
94  path_list = [
95      os.path.join(aom_dir, "av1/encoder"),
96      os.path.join(aom_dir, "av1/common")
97  ]
98  code_file_list = []
99  for path in path_list:
100    path = os.path.realpath(path)
101    code_file_list.extend(get_code_file_list(path, av1_exclude_file_set()))
102  modify_av1_rtcd(build_dir)
103  cmd = get_av1_pp_command(fake_header_dir, code_file_list) + " >" + output
104  os.chdir(build_dir)
105  os.system(cmd)
106  os.chdir(cur_dir)
107
108
109if __name__ == "__main__":
110  aom_dir = sys.argv[1]
111  build_dir = sys.argv[2]
112  fake_header_dir = sys.argv[3]
113  preprocess_av1(aom_dir, build_dir, fake_header_dir)
114