1ada8a9
diff -Nrup mozilla/config/external/moz.build mozilla-OK/config/external/moz.build
1ada8a9
--- mozilla/config/external/moz.build	2020-12-22 14:42:29.000000000 +0300
1ada8a9
+++ mozilla-OK/config/external/moz.build	2023-06-15 17:51:00.410300313 +0300
1ada8a9
@@ -32,8 +32,9 @@ if not CONFIG['MOZ_SYSTEM_LIBVPX']:
6f777c4
     external_dirs += ['media/libvpx']
6f777c4
 
6f777c4
 if CONFIG['MOZ_AV1']:
6f777c4
-    external_dirs += ['media/libaom']
6f777c4
-    external_dirs += ['media/libdav1d']
6f777c4
+    if not CONFIG['MOZ_SYSTEM_AV1']:
6f777c4
+        external_dirs += ['media/libaom']
6f777c4
+        external_dirs += ['media/libdav1d']
6f777c4
 
6f777c4
 if not CONFIG['MOZ_SYSTEM_PNG']:
6f777c4
     external_dirs += ['media/libpng']
1ada8a9
diff -Nrup mozilla/config/system-headers.mozbuild mozilla-OK/config/system-headers.mozbuild
1ada8a9
--- mozilla/config/system-headers.mozbuild	2023-06-10 13:40:55.000000000 +0300
1ada8a9
+++ mozilla-OK/config/system-headers.mozbuild	2023-06-15 17:51:00.410300313 +0300
1ada8a9
@@ -1285,6 +1285,14 @@ if CONFIG['MOZ_ENABLE_LIBPROXY']:
1ada8a9
         'proxy.h',
6f777c4
     ]
6f777c4
 
6f777c4
+if CONFIG['MOZ_SYSTEM_AV1']:
6f777c4
+    system_headers += [
6f777c4
+        'aom/aom_decoder.h',
6f777c4
+        'aom/aomdx.h',
6f777c4
+        'aom/aom_image.h',
6f777c4
+        'dav1d/dav1d.h',
6f777c4
+    ]
6f777c4
+
6f777c4
 if CONFIG['MOZ_SYSTEM_LIBVPX']:
6f777c4
     system_headers += [
6f777c4
         'vpx_mem/vpx_mem.h',
1ada8a9
diff -Nrup mozilla/dom/media/platforms/moz.build mozilla-OK/dom/media/platforms/moz.build
1ada8a9
--- mozilla/dom/media/platforms/moz.build	2023-06-10 13:40:55.000000000 +0300
1ada8a9
+++ mozilla-OK/dom/media/platforms/moz.build	2023-06-15 17:51:00.411300307 +0300
1ada8a9
@@ -74,6 +74,11 @@ if CONFIG['MOZ_AV1']:
6f777c4
         'agnostic/AOMDecoder.cpp',
6f777c4
         'agnostic/DAV1DDecoder.cpp',
6f777c4
     ]
6f777c4
+    if CONFIG['MOZ_SYSTEM_AV1']:
6f777c4
+        CXXFLAGS += CONFIG['MOZ_SYSTEM_LIBAOM_CFLAGS']
6f777c4
+        OS_LIBS += CONFIG['MOZ_SYSTEM_LIBAOM_LIBS']
6f777c4
+        CXXFLAGS += CONFIG['MOZ_SYSTEM_LIBDAV1D_CFLAGS']
6f777c4
+        OS_LIBS += CONFIG['MOZ_SYSTEM_LIBDAV1D_LIBS']
6f777c4
 
6f777c4
 if CONFIG['MOZ_APPLEMEDIA']:
6f777c4
   EXPORTS += [
1ada8a9
diff -Nrup mozilla/toolkit/moz.configure mozilla-OK/toolkit/moz.configure
1ada8a9
--- mozilla/toolkit/moz.configure	2023-06-10 13:41:26.000000000 +0300
1ada8a9
+++ mozilla-OK/toolkit/moz.configure	2023-06-15 17:51:00.411300307 +0300
1ada8a9
@@ -408,7 +408,23 @@ def av1(value):
6f777c4
     if value:
6f777c4
         return True
6f777c4
 
6f777c4
-@depends(target, nasm_version, when=av1 & compile_environment)
6f777c4
+option('--with-system-av1',
6f777c4
+       help="Use system av1 (located with pkgconfig)")
6f777c4
+
6f777c4
+system_libaom_info = pkg_check_modules('MOZ_SYSTEM_LIBAOM', 'aom >= 1.0.0',
6f777c4
+                                       when='--with-system-av1')
6f777c4
+
6f777c4
+system_libdav1d_info = pkg_check_modules('MOZ_SYSTEM_LIBDAV1D', 'dav1d >= 0.1.1',
6f777c4
+                                         when='--with-system-av1')
6f777c4
+
6f777c4
+@depends(system_libaom_info, system_libdav1d_info)
6f777c4
+def system_av1(system_libaom_info, system_libdav1d_info):
6f777c4
+    has_av1_libs = False
6f777c4
+    if system_libaom_info and system_libdav1d_info:
6f777c4
+        has_av1_libs = True
6f777c4
+    return has_av1_libs
6f777c4
+
6f777c4
+@depends(target, nasm_version, when=av1 & depends(system_av1)(lambda v: not v) & compile_environment)
6f777c4
 def dav1d_asm(target, nasm_version):
6f777c4
     if target.os != 'Android':
6f777c4
         if target.cpu == 'aarch64':
1ada8a9
@@ -424,6 +440,7 @@ set_config('MOZ_DAV1D_ASM', dav1d_asm)
6f777c4
 set_define('MOZ_DAV1D_ASM', dav1d_asm)
6f777c4
 set_config('MOZ_AV1', av1)
6f777c4
 set_define('MOZ_AV1', av1)
6f777c4
+set_config('MOZ_SYSTEM_AV1', depends_if(system_av1)(lambda _: True))
6f777c4
 
6f777c4
 # Built-in fragmented MP4 support.
6f777c4
 # ==============================================================