• 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'AOM_FORCE_INLINE='"
70                                                                         " "
71                                                                         "-D'inline='"
72                                                                         )
73  return pre_command + " " + " ".join(code_file_list)
74
75
76def modify_av1_rtcd(build_dir):
77  av1_rtcd = os.path.join(build_dir, "config/av1_rtcd.h")
78  fp = open(av1_rtcd)
79  string = fp.read()
80  fp.close()
81  new_string = string.replace("#ifdef RTCD_C", "#if 0")
82  fp = open(av1_rtcd, "w")
83  fp.write(new_string)
84  fp.close()
85
86
87def preprocess_av1(aom_dir, build_dir, fake_header_dir):
88  cur_dir = os.getcwd()
89  output = os.path.join(cur_dir, "av1_pp.c")
90  path_list = [
91      os.path.join(aom_dir, "av1/encoder"),
92      os.path.join(aom_dir, "av1/common")
93  ]
94  code_file_list = []
95  for path in path_list:
96    path = os.path.realpath(path)
97    code_file_list.extend(get_code_file_list(path, av1_exclude_file_set()))
98  modify_av1_rtcd(build_dir)
99  cmd = get_av1_pp_command(fake_header_dir, code_file_list) + " >" + output
100  os.chdir(build_dir)
101  os.system(cmd)
102  os.chdir(cur_dir)
103
104
105if __name__ == "__main__":
106  aom_dir = sys.argv[1]
107  build_dir = sys.argv[2]
108  fake_header_dir = sys.argv[3]
109  preprocess_av1(aom_dir, build_dir, fake_header_dir)
110