Bug 1393119 - Update gn files for mozilla build; r?jesup draft
authorDan Minor <dminor@mozilla.com>
Thu, 27 Jul 2017 13:04:25 -0400
changeset 713535 3727e8201580818d368335c017649720411997d2
parent 712784 a4120c6fc5c3a186ec32bae7080cf7b22a208b70
child 713536 d03946bb0e80d4f048ddea42e77815587aa0593d
push id93666
push userbmo:dminor@mozilla.com
push dateWed, 20 Dec 2017 15:10:53 +0000
reviewersjesup
bugs1393119
milestone59.0a1
Bug 1393119 - Update gn files for mozilla build; r?jesup MozReview-Commit-ID: KRaCt8uvTJH
build/gn.mozbuild
media/webrtc/moz.build
media/webrtc/trunk/BUILD.gn
media/webrtc/trunk/build/config/BUILD.gn
media/webrtc/trunk/build/config/BUILDCONFIG.gn
media/webrtc/trunk/build/config/android/BUILD.gn
media/webrtc/trunk/build/config/android/rules.gni
media/webrtc/trunk/build/config/arm.gni
media/webrtc/trunk/build/config/compiler/BUILD.gn
media/webrtc/trunk/build/config/features.gni
media/webrtc/trunk/build/config/linux/BUILD.gn
media/webrtc/trunk/build/config/posix/BUILD.gn
media/webrtc/trunk/build/config/sysroot.gni
media/webrtc/trunk/build/config/ui.gni
media/webrtc/trunk/build/mac/find_sdk.py
media/webrtc/trunk/build/toolchain/win/BUILD.gn
media/webrtc/trunk/build/win/BUILD.gn
media/webrtc/trunk/gtest/moz.build
media/webrtc/trunk/webrtc/BUILD.gn
media/webrtc/trunk/webrtc/api/BUILD.gn
media/webrtc/trunk/webrtc/base/BUILD.gn
media/webrtc/trunk/webrtc/base/sigslot.h
media/webrtc/trunk/webrtc/build/webrtc.gni
media/webrtc/trunk/webrtc/call/BUILD.gn
media/webrtc/trunk/webrtc/logging/BUILD.gn
media/webrtc/trunk/webrtc/media/BUILD.gn
media/webrtc/trunk/webrtc/modules/BUILD.gn
media/webrtc/trunk/webrtc/modules/audio_coding/BUILD.gn
media/webrtc/trunk/webrtc/modules/audio_coding/audio_coding.gni
media/webrtc/trunk/webrtc/modules/audio_device/BUILD.gn
media/webrtc/trunk/webrtc/modules/audio_processing/BUILD.gn
media/webrtc/trunk/webrtc/modules/congestion_controller/BUILD.gn
media/webrtc/trunk/webrtc/modules/desktop_capture/BUILD.gn
media/webrtc/trunk/webrtc/modules/desktop_capture/win/cursor.cc
media/webrtc/trunk/webrtc/modules/remote_bitrate_estimator/BUILD.gn
media/webrtc/trunk/webrtc/modules/video_capture/BUILD.gn
media/webrtc/trunk/webrtc/modules/video_coding/BUILD.gn
media/webrtc/trunk/webrtc/modules/video_processing/BUILD.gn
media/webrtc/trunk/webrtc/system_wrappers/BUILD.gn
media/webrtc/trunk/webrtc/video/BUILD.gn
media/webrtc/trunk/webrtc/video_engine/BUILD.gn
--- a/build/gn.mozbuild
+++ b/build/gn.mozbuild
@@ -24,14 +24,14 @@ flavors = {
     'FreeBSD': 'freebsd',
     'NetBSD': 'netbsd',
     'OpenBSD': 'openbsd',
 }
 gn_vars['target_os'] = flavors.get(os)
 
 arches = {
     'x86_64': 'x64',
-    'x86': 'ia32',
+    'x86': 'x86',
     'aarch64': 'arm64',
 }
 
 gn_vars['host_cpu'] = arches.get(CONFIG['HOST_CPU_ARCH'], CONFIG['HOST_CPU_ARCH'])
 gn_vars['target_cpu'] = arches.get(CONFIG['CPU_ARCH'], CONFIG['CPU_ARCH'])
--- a/media/webrtc/moz.build
+++ b/media/webrtc/moz.build
@@ -68,17 +68,18 @@ elif CONFIG['MOZ_TSAN']:
     gyp_vars_copy.update(build_for_tool="tsan")
 
 GN_DIRS += ['trunk']
 
 gn_vars_copy = gn_vars.copy()
 
 GN_DIRS['trunk'].variables = gn_vars_copy
 GN_DIRS['trunk'].mozilla_flags = [
-    "-fobjc-arc"
+    '-fobjc-arc',
+    '-mfpu=neon',
 ]
 
 # We allow warnings for third-party code that can be updated from upstream.
 GN_DIRS['trunk'].sandbox_vars['COMPILE_FLAGS'] = {'WARNINGS_AS_ERRORS': []}
 GN_DIRS['trunk'].sandbox_vars['FINAL_LIBRARY'] = 'webrtc'
 GN_DIRS['trunk'].non_unified_sources += webrtc_non_unified_sources
 
 if CONFIG['MOZ_WEBRTC_SIGNALING']:
--- a/media/webrtc/trunk/BUILD.gn
+++ b/media/webrtc/trunk/BUILD.gn
@@ -7,15 +7,21 @@
 # be found in the AUTHORS file in the root of the source tree.
 
 import("webrtc/build/webrtc.gni")
 
 group("default") {
   testonly = true
   deps = [
     "//webrtc",
-    "//webrtc/examples",
-    "//webrtc/tools",
   ]
+
+  if (!build_with_mozilla) {
+    deps += [
+      "//webrtc/examples",
+      "//webrtc/tools",
+    ]
+  }
+
   if (rtc_include_tests) {
     deps += [ "//webrtc:webrtc_tests" ]
   }
 }
--- a/media/webrtc/trunk/build/config/BUILD.gn
+++ b/media/webrtc/trunk/build/config/BUILD.gn
@@ -18,17 +18,17 @@ declare_args() {
   # Iterator debugging is always off in release builds (technically, this flag
   # affects the "debug" config, which is always available but applied by
   # default only in debug builds).
   #
   # Iterator debugging is generally useful for catching bugs. But it can
   # introduce extra locking to check the state of an iterator against the state
   # of the current object. For iterator- and thread-heavy code, this can
   # significantly slow execution.
-  enable_iterator_debugging = true
+  enable_iterator_debugging = !build_with_mozilla
 }
 
 # ==============================================
 #   PLEASE DO NOT ADD MORE THINGS TO THIS LIST
 # ==============================================
 #
 # Legacy feature defines applied to all targets.
 #
@@ -44,17 +44,19 @@ declare_args() {
 # See //build/buildflag_header.gni for inntructions on generating headers.
 #
 # This will also allow you to scope your build flag to a BUILD.gn file (or a
 # .gni file if you need it from more than one place) rather than making global
 # flags. See //build/config/BUILDCONFIG.gn for advice on where to define
 # build flags.
 config("feature_flags") {
   # Don't use deprecated V8 APIs anywhere.
-  defines = [ "V8_DEPRECATION_WARNINGS" ]
+  defines = []
+  defines += [ "V8_DEPRECATION_WARNINGS" ]
+
   if (dcheck_always_on) {
     defines += [ "DCHECK_ALWAYS_ON=1" ]
   }
   if (use_udev) {
     # TODO(brettw) should probably be "=1".
     defines += [ "USE_UDEV" ]
   }
   if (use_ash) {
@@ -131,36 +133,40 @@ config("feature_flags") {
     defines += [ "CHROMIUM_BUILD" ]
   }
   if (is_syzyasan) {
     defines += [
       "SYZYASAN",
       "MEMORY_SANITIZER_INITIAL_SIZE",
     ]
   }
-  if (!fieldtrial_testing_like_official_build && !is_chrome_branded) {
+  if (!fieldtrial_testing_like_official_build && !is_chrome_branded
+      && !build_with_mozilla) {
     defines += [ "FIELDTRIAL_TESTING_ENABLED" ]
   }
 
   # ==============================================
   #   PLEASE DO NOT ADD MORE THINGS TO THIS LIST
   # ==============================================
   #
   # See the comment at the top.
 }
 
 # Debug/release ----------------------------------------------------------------
 
 config("debug") {
   defines = [
-    "_DEBUG",
     "DYNAMIC_ANNOTATIONS_ENABLED=1",
     "WTF_USE_DYNAMIC_ANNOTATIONS=1",
   ]
 
+  if (!build_with_mozilla) {
+    defines += [ "_DEBUG" ]
+  }
+
   if (is_nacl) {
     defines += [ "DYNAMIC_ANNOTATIONS_PREFIX=NACL_" ]
   }
 
   if (is_win) {
     if (!enable_iterator_debugging) {
       # Iterator debugging is enabled by default by the compiler on debug
       # builds, and we have to tell it to turn it off.
--- a/media/webrtc/trunk/build/config/BUILDCONFIG.gn
+++ b/media/webrtc/trunk/build/config/BUILDCONFIG.gn
@@ -117,16 +117,21 @@ if (current_os == "") {
 #   your feature) rather than just "foo".
 #
 # - Write good comments directly above the declaration with no blank line.
 #   These comments will appear as documentation in "gn args --list".
 #
 # - Don't call exec_script inside declare_args. This will execute the script
 #   even if the value is overridden, which is wasteful. See first bullet.
 
+# Enable to use the Mozilla internal settings.
+declare_args() {
+  build_with_mozilla = true
+}
+
 declare_args() {
   # Set to enable the official build level of optimization. This has nothing
   # to do with branding, but enables an additional level of optimization above
   # release (!is_debug). This might be better expressed as a tri-state
   # (debug, release, official) but for historical reasons there are two
   # separate flags.
   is_official_build = false
 
@@ -160,17 +165,17 @@ declare_args() {
 declare_args() {
   # Component build. Setting to true compiles targets declared as "components"
   # as shared libraries loaded dynamically. This speeds up development time.
   # When false, components will be linked statically.
   #
   # For more information see
   # https://chromium.googlesource.com/chromium/src/+/master/docs/component_build.md
   is_component_build =
-      is_debug && current_os != "ios" && current_os != "fuchsia"
+      is_debug && current_os != "ios" && current_os != "fuchsia" && !build_with_mozilla
 }
 
 assert(!(is_debug && is_official_build), "Can't do official debug builds")
 
 # ==============================================================================
 # TOOLCHAIN SETUP
 # ==============================================================================
 #
--- a/media/webrtc/trunk/build/config/android/BUILD.gn
+++ b/media/webrtc/trunk/build/config/android/BUILD.gn
@@ -119,73 +119,75 @@ config("runtime_library") {
         rebase_path("$android_ndk_root/sources/android/support/include",
                     root_build_dir),
   ]
 
   defines = [ "__GNU_SOURCE=1" ]  # Necessary for clone().
   ldflags = [ "-nostdlib" ]
   lib_dirs = [ android_libcpp_lib_dir ]
 
-  # The libc++ runtime library (must come first).
-  # ASan needs to dynamically link to libc++ even in static builds so
-  # that it can interpose operator new.
-  if (is_component_build || is_asan) {
-    libs = [ "c++_shared" ]
-  } else {
-    libs = [ "c++_static" ]
-  }
-  libs += [
-    "c++abi",
-    "android_support",
-  ]
-
-  # arm builds of libc++ starting in NDK r12 depend on unwind.
-  if (current_cpu == "arm") {
-    libs += [ "unwind" ]
-  }
+  if (!build_with_mozilla) {
+    # The libc++ runtime library (must come first).
+    # ASan needs to dynamically link to libc++ even in static builds so
+    # that it can interpose operator new.
+    if (is_component_build || is_asan) {
+      libs = [ "c++_shared" ]
+    } else {
+      libs = [ "c++_static" ]
+    }
+    libs += [
+      "c++abi",
+      "android_support",
+    ]
 
-  # Manually link the libgcc.a that the cross compiler uses. This is
-  # absolute because the linker will look inside the sysroot if it's not.
-  libs += [
-    rebase_path(android_libgcc_file),
-    "c",
-  ]
+    # arm builds of libc++ starting in NDK r12 depend on unwind.
+    if (current_cpu == "arm") {
+      libs += [ "unwind" ]
+    }
 
-  # Clang with libc++ does not require an explicit atomic library reference.
-  if (!is_clang) {
-    libs += [ "atomic" ]
-  }
-
-  if (is_clang) {
-    # Work around incompatibilities between bionic and clang headers.
-    defines += [
-      "__compiler_offsetof=__builtin_offsetof",
-      "nan=__builtin_nan",
+    # Manually link the libgcc.a that the cross compiler uses. This is
+    # absolute because the linker will look inside the sysroot if it's not.
+    libs += [
+      rebase_path(android_libgcc_file),
+      "c",
     ]
 
-    if (current_cpu == "x64" || current_cpu == "arm64" ||
-        current_cpu == "mips64el") {
-      # 64-bit targets build with NDK 21, 32-bit targets with NDK 16
-      # (see ./config.gni).  When using clang, NDK 21 defines snprintf to
-      # something for a kind of for of _FORTIFY_SOURCE support, see
-      # third_party/android_tools/ndk/platforms/android-21/arch-x86_64/usr/include/stdio.h
-      # Making snprintf a macro breaks base/strings/string_utils.h which
-      # defines base::snprintf().  So define snprintf to itself to force the
-      # NDK to not redefine it.  This disables _chk for snprintf, but since
-      # 32-bit versions use NDK 16 which doesn't have any fortify support, that
-      # seems ok.  b/32067310 tracks better fortify support with clang.
-      # TODO(thakis): Remove this once b/32067310 is fixed.
-      defines += [ "snprintf=snprintf" ]
+    # Clang with libc++ does not require an explicit atomic library reference.
+    if (!is_clang) {
+      libs += [ "atomic" ]
     }
-  }
+
+    if (is_clang) {
+      # Work around incompatibilities between bionic and clang headers.
+      defines += [
+        "__compiler_offsetof=__builtin_offsetof",
+        "nan=__builtin_nan",
+      ]
 
-  # TODO(jdduke) Re-enable on mips after resolving linking
-  # issues with libc++ (crbug.com/456380).
-  if (current_cpu != "mipsel" && current_cpu != "mips64el") {
-    ldflags += [ "-Wl,--warn-shared-textrel" ]
+      if (current_cpu == "x64" || current_cpu == "arm64" ||
+          current_cpu == "mips64el") {
+        # 64-bit targets build with NDK 21, 32-bit targets with NDK 16
+        # (see ./config.gni).  When using clang, NDK 21 defines snprintf to
+        # something for a kind of for of _FORTIFY_SOURCE support, see
+        # third_party/android_tools/ndk/platforms/android-21/arch-x86_64/usr/include/stdio.h
+        # Making snprintf a macro breaks base/strings/string_utils.h which
+        # defines base::snprintf().  So define snprintf to itself to force the
+        # NDK to not redefine it.  This disables _chk for snprintf, but since
+        # 32-bit versions use NDK 16 which doesn't have any fortify support, that
+        # seems ok.  b/32067310 tracks better fortify support with clang.
+        # TODO(thakis): Remove this once b/32067310 is fixed.
+        defines += [ "snprintf=snprintf" ]
+      }
+    }
+
+    # TODO(jdduke) Re-enable on mips after resolving linking
+    # issues with libc++ (crbug.com/456380).
+    if (current_cpu != "mipsel" && current_cpu != "mips64el") {
+      ldflags += [ "-Wl,--warn-shared-textrel" ]
+    }
   }
 }
 
 config("executable_config") {
   cflags = [ "-fPIE" ]
   asmflags = [ "-fPIE" ]
   ldflags = [ "-pie" ]
 }
--- a/media/webrtc/trunk/build/config/android/rules.gni
+++ b/media/webrtc/trunk/build/config/android/rules.gni
@@ -1,16 +1,18 @@
 # Copyright 2014 The Chromium Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
 # Do not add any imports to non-//build directories here.
 # Some projects (e.g. V8) do not have non-build directories DEPS'ed in.
 import("//build/config/android/config.gni")
-import("//build/config/android/internal_rules.gni")
+if (!build_with_mozilla) {
+  import("//build/config/android/internal_rules.gni")
+}
 import("//build/config/compiler/compiler.gni")
 import("//build/config/dcheck_always_on.gni")
 import("//build/toolchain/toolchain.gni")
 
 assert(is_android)
 
 # Creates a dist directory for a native executable.
 #
@@ -139,17 +141,20 @@ template("wrapper_script") {
     if (defined(invoker.flag_name)) {
       args += [ "--flag-name=${invoker.flag_name}" ]
     }
   }
 }
 
 if (enable_java_templates) {
   import("//build/config/sanitizers/sanitizers.gni")
-  import("//tools/grit/grit_rule.gni")
+
+  if (!build_with_mozilla) {
+    import("//tools/grit/grit_rule.gni")
+  }
 
   # Declare a jni target
   #
   # This target generates the native jni bindings for a set of .java files.
   #
   # See base/android/jni_generator/jni_generator.py for more info about the
   # format of generating JNI bindings.
   #
--- a/media/webrtc/trunk/build/config/arm.gni
+++ b/media/webrtc/trunk/build/config/arm.gni
@@ -42,17 +42,17 @@ if (current_cpu == "arm" || v8_current_c
     # has increased code density.
     arm_use_thumb = true
   }
 
   assert(arm_float_abi == "" || arm_float_abi == "hard" ||
          arm_float_abi == "soft" || arm_float_abi == "softfp")
 
   if (arm_use_neon == "") {
-    if (current_os == "linux" && target_cpu != v8_target_cpu) {
+    if (current_os == "linux" && target_cpu != v8_target_cpu && !build_with_mozilla) {
       # Don't use neon on V8 simulator builds as a default.
       arm_use_neon = false
     } else {
       arm_use_neon = true
     }
   }
 
   if (arm_version == 6) {
--- a/media/webrtc/trunk/build/config/compiler/BUILD.gn
+++ b/media/webrtc/trunk/build/config/compiler/BUILD.gn
@@ -289,17 +289,17 @@ config("compiler") {
       # id, so explicitly enable it in official builds. It's not needed in
       # unofficial builds and computing it does slow down the link, so go with
       # faster links in unofficial builds.
       ldflags += [ "-Wl,--build-id=sha1" ]
     }
 
     defines += [ "_FILE_OFFSET_BITS=64" ]
 
-    if (!is_android) {
+    if (!is_android && !build_with_mozilla) {
       defines += [
         "_LARGEFILE_SOURCE",
         "_LARGEFILE64_SOURCE",
       ]
     }
 
     if (!is_nacl) {
       if (exclude_unwind_tables) {
@@ -1151,20 +1151,23 @@ config("chromium_code") {
     }
     if (is_clang) {
       # Enable -Wextra for chromium_code when we control the compiler.
       cflags += [ "-Wextra" ]
     }
 
     # In Chromium code, we define __STDC_foo_MACROS in order to get the
     # C99 macros on Mac and Linux.
-    defines = [
-      "__STDC_CONSTANT_MACROS",
-      "__STDC_FORMAT_MACROS",
-    ]
+    defines = []
+    if (!build_with_mozilla) {
+      defines += [
+        "__STDC_CONSTANT_MACROS",
+        "__STDC_FORMAT_MACROS",
+      ]
+    }
 
     if (!is_debug && !using_sanitizer &&
         (!is_linux || !is_clang || is_official_build) &&
         current_cpu != "s390x" && current_cpu != "s390" &&
         current_cpu != "ppc64" && current_cpu != "ppc64") {
       # _FORTIFY_SOURCE isn't really supported by Clang now, see
       # http://llvm.org/bugs/show_bug.cgi?id=16821.
       # It seems to work fine with Ubuntu 12 headers though, so use it in
--- a/media/webrtc/trunk/build/config/features.gni
+++ b/media/webrtc/trunk/build/config/features.gni
@@ -36,31 +36,31 @@ declare_args() {
   # Note: this flag is used by WebRTC which is DEPSed into Chrome. Moving it
   # out of //build will require using the build_overrides directory.
   proprietary_codecs = is_chrome_branded || is_chromecast
 
   # Variable safe_browsing is used to control the build time configuration for
   # safe browsing feature. Safe browsing can be compiled in 3 different levels:
   # 0 disables it, 1 enables it fully, and 2 enables mobile protection via an
   # external API.
-  if (is_ios || is_chromecast) {
+  if (is_ios || is_chromecast || build_with_mozilla) {
     safe_browsing_mode = 0
   } else if (is_android) {
     safe_browsing_mode = 2
   } else {
     safe_browsing_mode = 1
   }
 
   # Set to true make a build that disables activation of field trial tests
   # specified in testing/variations/fieldtrial_testing_config_*.json.
   # Note: this setting is ignored if is_chrome_branded.
   fieldtrial_testing_like_official_build = is_chrome_branded
 
   # libudev usage. This currently only affects the content layer.
-  use_udev = is_linux && !is_chromecast
+  use_udev = is_linux && !is_chromecast && !build_with_mozilla
 
   use_dbus = is_linux && !is_chromecast
 
   # Option controlling the use of GConf (the classic GNOME configuration
   # system).
   use_gconf = is_linux && !is_chromeos && !is_chromecast
 
   use_gio = is_linux && !is_chromeos && !is_chromecast
--- a/media/webrtc/trunk/build/config/linux/BUILD.gn
+++ b/media/webrtc/trunk/build/config/linux/BUILD.gn
@@ -34,18 +34,23 @@ config("x11") {
     "xcb",
     "Xcomposite",
     "Xcursor",
     "Xdamage",
     "Xext",
     "Xfixes",
     "Xi",
     "Xrender",
-    "Xtst",
   ]
+
+  if (!build_with_mozilla) {
+    libs += [
+      "Xtst",
+    ]
+  }
 }
 
 config("xcomposite") {
   libs = [ "Xcomposite" ]
 }
 
 config("xext") {
   libs = [ "Xext" ]
@@ -66,18 +71,20 @@ config("xfixes") {
 config("libcap") {
   libs = [ "cap" ]
 }
 
 config("xi") {
   libs = [ "Xi" ]
 }
 
-config("xtst") {
-  libs = [ "Xtst" ]
+if (!build_with_mozilla) {
+  config("xtst") {
+    libs = [ "Xtst" ]
+  }
 }
 
 config("libresolv") {
   libs = [ "resolv" ]
 }
 
 if (use_glib) {
   pkg_config("glib") {
--- a/media/webrtc/trunk/build/config/posix/BUILD.gn
+++ b/media/webrtc/trunk/build/config/posix/BUILD.gn
@@ -13,17 +13,17 @@ group("posix") {
   visibility = [ "//:optimize_gn_gen" ]
 }
 
 # This is included by reference in the //build/config/compiler:runtime_library
 # config that is applied to all targets. It is here to separate out the logic
 # that is Posix-only. Please see that target for advice on what should go in
 # :runtime_library vs. :compiler.
 config("runtime_library") {
-  if (!is_mac && !is_ios && sysroot != "") {
+  if (!is_mac && !is_ios && sysroot != "" && !build_with_mozilla) {
     # Pass the sysroot to all C compiler variants, the assembler, and linker.
     cflags = [ "--sysroot=" + rebase_path(sysroot, root_build_dir) ]
     asmflags = cflags
     ldflags = cflags
 
     # Need to get some linker flags out of the sysroot.
     ld_paths = exec_script("sysroot_ld_path.py",
                            [
--- a/media/webrtc/trunk/build/config/sysroot.gni
+++ b/media/webrtc/trunk/build/config/sysroot.gni
@@ -11,17 +11,18 @@ declare_args() {
   # The absolute path of the sysroot that is applied when compiling using
   # the target toolchain.
   target_sysroot = ""
 
   # The absolute path to directory containing linux sysroot images
   target_sysroot_dir = "//build/linux"
 
   use_sysroot = current_cpu != "s390x" && current_cpu != "s390" &&
-                current_cpu != "ppc64" && current_cpu != "ppc"
+                current_cpu != "ppc64" && current_cpu != "ppc" &&
+                !build_with_mozilla
 }
 
 if (current_os == target_os && current_cpu == target_cpu &&
     target_sysroot != "") {
   sysroot = target_sysroot
 } else if (is_android) {
   import("//build/config/android/config.gni")
   if (current_cpu == "x86") {
--- a/media/webrtc/trunk/build/config/ui.gni
+++ b/media/webrtc/trunk/build/config/ui.gni
@@ -26,20 +26,20 @@ declare_args() {
 
   # Indicates if Ozone is enabled. Ozone is a low-level library layer for Linux
   # that does not require X11. Enabling this feature disables use of glib, x11,
   # Pango, and Cairo. Default to false on non-Chromecast builds.
   use_ozone = is_chromeos || (is_chromecast && !is_android)
 
   # Indicates if Aura is enabled. Aura is a low-level windowing library, sort
   # of a replacement for GDI or GTK.
-  use_aura = is_win || is_linux
+  use_aura = (is_win || is_linux) && !build_with_mozilla
 
   # Whether we should use glib, a low level C utility library.
-  use_glib = is_linux
+  use_glib = is_linux && !build_with_mozilla
 }
 
 declare_args() {
   # True means the UI is built using the "views" framework.
   toolkit_views =
       (is_mac || is_win || is_chromeos || use_aura) && !is_chromecast
 }
 
@@ -50,17 +50,17 @@ declare_args() {
 # Indicates if the UI toolkit depends on X11.
 use_x11 = is_linux && !use_ozone
 
 # Turn off glib if Ozone is enabled.
 if (use_ozone) {
   use_glib = false
 }
 
-if (is_linux && !use_ozone) {
+if (is_linux && !use_ozone && !build_with_mozilla) {
   use_cairo = true
   use_pango = true
 } else {
   use_cairo = false
   use_pango = false
 }
 
 # Whether to use atk, the Accessibility ToolKit library
--- a/media/webrtc/trunk/build/mac/find_sdk.py
+++ b/media/webrtc/trunk/build/mac/find_sdk.py
@@ -79,12 +79,16 @@ def main():
   if options.print_sdk_path:
     print subprocess.check_output(
         ['xcrun', '-sdk', 'macosx' + best_sdk, '--show-sdk-path']).strip()
 
   return best_sdk
 
 
 if __name__ == '__main__':
-  if sys.platform != 'darwin':
-    raise Exception("This script only runs on Mac")
-  print main()
+  if sys.platform == 'darwin':
+    print main()
+  else:
+    # Mozilla builds cross-compile on Linux, so return some fake data to keep
+    # the build system happy. These values aren't used anywhere.
+    print "."
+    print "."
   sys.exit(0)
--- a/media/webrtc/trunk/build/toolchain/win/BUILD.gn
+++ b/media/webrtc/trunk/build/toolchain/win/BUILD.gn
@@ -25,17 +25,17 @@ tool_wrapper_path = rebase_path("tool_wr
 if (use_goma) {
   goma_prefix = "$goma_dir/gomacc.exe "
 } else {
   goma_prefix = ""
 }
 
 # Copy the VS runtime DLL for the default toolchain to the root build directory
 # so things will run.
-if (current_toolchain == default_toolchain) {
+if (current_toolchain == default_toolchain && !build_with_mozilla) {
   if (is_debug) {
     configuration_name = "Debug"
   } else {
     configuration_name = "Release"
   }
   exec_script("../../vs_toolchain.py",
               [
                 "copy_dlls",
@@ -326,76 +326,100 @@ if (host_os == "win") {
 } else {
   clang_cl = "clang-cl"
 }
 
 # 32-bit toolchains. Only define these when the target architecture is 32-bit
 # since we don't do any 32-bit cross compiles when targeting 64-bit (the
 # build does generate some 64-bit stuff from 32-bit target builds).
 if (target_cpu == "x86") {
-  x86_toolchain_data = exec_script("setup_toolchain.py",
-                                   [
-                                     visual_studio_path,
-                                     windows_sdk_path,
-                                     visual_studio_runtime_dirs,
-                                     "x86",
-                                   ],
-                                   "scope")
+  if (!build_with_mozilla) {
+    x86_toolchain_data = exec_script("setup_toolchain.py",
+                                     [
+                                       visual_studio_path,
+                                       windows_sdk_path,
+                                       visual_studio_runtime_dirs,
+                                       "x86",
+                                     ],
+                                     "scope")
+  }
 
   msvc_toolchain("x86") {
     environment = "environment.x86"
-    cl = "${goma_prefix}\"${x86_toolchain_data.vc_bin_dir}/cl.exe\""
+    if (!build_with_mozilla) {
+      cl = "${goma_prefix}\"${x86_toolchain_data.vc_bin_dir}/cl.exe\""
+    } else {
+      cl = ""
+    }
     toolchain_args = {
       current_cpu = "x86"
       is_clang = false
     }
   }
 
   msvc_toolchain("clang_x86") {
     environment = "environment.x86"
-    prefix = rebase_path("$clang_base_path/bin", root_build_dir)
-    cl = "${goma_prefix}$prefix/${clang_cl}"
-    sys_include_flags = "${x86_toolchain_data.include_flags_imsvc}"
+
+    if (!build_with_mozilla) {
+      prefix = rebase_path("$clang_base_path/bin", root_build_dir)
+      cl = "${goma_prefix}$prefix/${clang_cl}"
+      sys_include_flags = "${x86_toolchain_data.include_flags_imsvc}"
+    } else {
+      cl = ""
+      sys_include_flags = ""
+    }
 
     toolchain_args = {
       current_cpu = "x86"
       is_clang = true
     }
   }
 }
 
 # 64-bit toolchains.
-x64_toolchain_data = exec_script("setup_toolchain.py",
-                                 [
-                                   visual_studio_path,
-                                   windows_sdk_path,
-                                   visual_studio_runtime_dirs,
-                                   "x64",
-                                 ],
-                                 "scope")
+if (!build_with_mozilla) {
+  x64_toolchain_data = exec_script("setup_toolchain.py",
+                                   [
+                                     visual_studio_path,
+                                     windows_sdk_path,
+                                     visual_studio_runtime_dirs,
+                                     "x64",
+                                   ],
+                                   "scope")
+}
 
 template("win_x64_toolchains") {
   msvc_toolchain(target_name) {
     environment = "environment.x64"
-    cl = "${goma_prefix}\"${x64_toolchain_data.vc_bin_dir}/cl.exe\""
+
+    if (!build_with_mozilla) {
+      cl = "${goma_prefix}\"${x64_toolchain_data.vc_bin_dir}/cl.exe\""
+    } else {
+      cl = ""
+    }
 
     toolchain_args = {
       if (defined(invoker.toolchain_args)) {
         forward_variables_from(invoker.toolchain_args, "*")
       }
       is_clang = false
       current_cpu = "x64"
     }
   }
 
   msvc_toolchain("clang_" + target_name) {
     environment = "environment.x64"
-    prefix = rebase_path("$clang_base_path/bin", root_build_dir)
-    cl = "${goma_prefix}$prefix/${clang_cl}"
-    sys_include_flags = "${x64_toolchain_data.include_flags_imsvc}"
+    if (!build_with_mozilla) {
+      prefix = rebase_path("$clang_base_path/bin", root_build_dir)
+      cl = "${goma_prefix}$prefix/${clang_cl}"
+      sys_include_flags = "${x64_toolchain_data.include_flags_imsvc}"
+    } else {
+      cl = ""
+      sys_include_flags = ""
+    }
 
     toolchain_args = {
       if (defined(invoker.toolchain_args)) {
         forward_variables_from(invoker.toolchain_args, "*")
       }
       is_clang = true
       current_cpu = "x64"
     }
@@ -423,26 +447,34 @@ win_x64_toolchains("nacl_win64") {
 #
 # NOTE: This is currently broken because it references vc_bin_dir. brettw@
 # changed this around a bit, and I don't know what this should be set to
 # in terms of what setup_toolchain returns for a certain CPU architecture.
 if (target_os == "winrt_81" || target_os == "winrt_81_phone" ||
     target_os == "winrt_10") {
   msvc_toolchain("winrt_x86") {
     environment = "environment.winrt_x86"
-    cl = "${goma_prefix}\"${vc_bin_dir}/cl.exe\""
+    if (!build_with_mozilla) {
+      cl = "${goma_prefix}\"${vc_bin_dir}/cl.exe\""
+    } else {
+      cl = ""
+    }
 
     toolchain_args = {
       is_clang = false
       current_cpu = "x86"
     }
   }
 
   msvc_toolchain("winrt_x64") {
     environment = "environment.winrt_x64"
-    cl = "${goma_prefix}\"${vc_bin_dir}/cl.exe\""
+    if (!build_with_mozilla) {
+      cl = "${goma_prefix}\"${vc_bin_dir}/cl.exe\""
+    } else {
+      cl = ""
+    }
 
     toolchain_args = {
       is_clang = false
       current_cpu = "x64"
     }
   }
 }
--- a/media/webrtc/trunk/build/win/BUILD.gn
+++ b/media/webrtc/trunk/build/win/BUILD.gn
@@ -10,17 +10,17 @@ windows_manifest("default_exe_manifest")
   sources = [
     as_invoker_manifest,
     common_controls_manifest,
     default_compatibility_manifest,
   ]
   type = "exe"
 }
 
-if (is_win) {
+if (is_win && !build_with_mozilla) {
   action("copy_cdb_to_output") {
     script = "//build/win/copy_cdb_to_output.py"
     inputs = [
       script,
     ]
     outputs = [
       "$root_out_dir/cdb/cdb.exe",
       "$root_out_dir/cdb/dbgeng.dll",
--- a/media/webrtc/trunk/gtest/moz.build
+++ b/media/webrtc/trunk/gtest/moz.build
@@ -28,16 +28,17 @@ LOCAL_INCLUDES += [
     '/media/libopus/src',
     '/media/libyuv/libyuv/include',
 ]
 
 USE_LIBS += [
     '/media/webrtc/trunk/third_party/gflags/gflags_gflags/gflags',
     '/testing/gtest/gtest',
     'media_libopus',
+    'mozglue',
     'speex',
     'webrtc',
     'webrtc_common_gn',
     'webrtc_gn',
     'webrtc_i420_gn',
     # 'webrtc_utility',
     'webrtc_vp8_gn',
     'webrtc_vp9_gn',
--- a/media/webrtc/trunk/webrtc/BUILD.gn
+++ b/media/webrtc/trunk/webrtc/BUILD.gn
@@ -6,17 +6,19 @@
 # in the file PATENTS.  All contributing project authors may
 # be found in the AUTHORS file in the root of the source tree.
 
 # TODO(kjellander): Rebase this to webrtc/build/common.gypi changes after r6330.
 
 import("//build/config/linux/pkg_config.gni")
 import("//build/config/sanitizers/sanitizers.gni")
 import("build/webrtc.gni")
-import("//third_party/protobuf/proto_library.gni")
+if (!build_with_mozilla) {
+  import("//third_party/protobuf/proto_library.gni")
+}
 if (is_android) {
   import("//build/config/android/config.gni")
   import("//build/config/android/rules.gni")
 }
 
 # Contains the defines and includes in common.gypi that are duplicated both as
 # target_defaults and direct_dependent_settings.
 config("common_inherited_config") {
@@ -69,16 +71,22 @@ config("common_inherited_config") {
       "_CRT_SECURE_NO_WARNINGS",  # Suppress warnings about _vsnprinf
     ]
   }
   if (is_android) {
     defines += [
       "WEBRTC_LINUX",
       "WEBRTC_ANDROID",
     ]
+
+    if (build_with_mozilla) {
+      defines += [
+        "WEBRTC_ANDROID_OPENSLES",
+      ]
+    }
   }
   if (is_chromeos) {
     defines += [ "CHROMEOS" ]
   }
 
   if (rtc_sanitize_coverage != "") {
     assert(is_clang, "sanitizer coverage requires clang")
     cflags += [ "-fsanitize-coverage=${rtc_sanitize_coverage}" ]
@@ -239,36 +247,51 @@ if (!build_with_chromium) {
       "call.h",
       "config.h",
     ]
 
     defines = []
 
     deps = [
       ":webrtc_common",
-#      "api",
       "api:transport_api",
       "audio",
       "base",
       "call",
       "common_audio",
       "common_video",
-      "logging",
       "media",
       "modules",
       "modules/video_capture:video_capture_internal_impl",
-      "p2p",
-      "pc",
       "sdk",
-      "stats",
       "system_wrappers",
       "video",
       "voice_engine",
     ]
 
+    if (build_with_mozilla) {
+      deps += [
+        "api:video_frame_api",
+        "system_wrappers:field_trial_default",
+        "system_wrappers:metrics_default",
+      ]
+
+      if (!is_android) {
+        deps += [ "video_engine" ]
+      }
+    } else {
+      deps += [
+        "api",
+        "logging",
+        "p2p",
+        "pc",
+        "stats",
+      ]
+    }
+
     if (rtc_enable_protobuf) {
       defines += [ "ENABLE_RTC_EVENT_LOG" ]
       deps += [ "logging:rtc_event_log_proto" ]
     }
   }
 
   if (rtc_include_tests) {
     # Target to build all the WebRTC tests (but not examples or tools).
--- a/media/webrtc/trunk/webrtc/api/BUILD.gn
+++ b/media/webrtc/trunk/webrtc/api/BUILD.gn
@@ -8,19 +8,23 @@
 
 import("../build/webrtc.gni")
 if (is_android) {
   import("//build/config/android/config.gni")
   import("//build/config/android/rules.gni")
 }
 
 group("api") {
-  public_deps = [
-    ":libjingle_peerconnection",
-  ]
+  public_deps = []
+
+  if (!build_with_mozilla) {
+    public_deps += [
+      ":libjingle_peerconnection",
+    ]
+  }
 }
 
 rtc_source_set("call_api") {
   sources = [
     "call/audio_sink.h",
   ]
 
   deps = [
@@ -312,25 +316,30 @@ if (rtc_include_tests) {
         "//testing/android/native_test:native_test_support",
         "//webrtc/sdk/android:libjingle_peerconnection_java",
         "//webrtc/sdk/android:libjingle_peerconnection_jni",
       ]
     }
 
     deps += [
       ":fakemetricsobserver",
-      ":libjingle_peerconnection",
       "..:webrtc_common",
       "../base:rtc_base_tests_utils",
       "../media:rtc_unittest_main",
       "../pc:rtc_pc",
       "../system_wrappers:metrics_default",
       "//testing/gmock",
     ]
 
+    if (!build_with_mozilla) {
+      deps += [
+        ":libjingle_peerconnection",
+      ]
+    }
+
     if (is_android) {
       deps += [ "//testing/android/native_test:native_test_support" ]
 
       shard_timeout = 900
     }
   }
 
   rtc_source_set("mock_audio_mixer") {
@@ -351,17 +360,23 @@ if (rtc_include_tests) {
 
   rtc_source_set("fakemetricsobserver") {
     testonly = true
     sources = [
       "fakemetricsobserver.cc",
       "fakemetricsobserver.h",
     ]
     deps = [
-      ":libjingle_peerconnection",
       "../base:rtc_base_approved",
     ]
+
     if (!build_with_chromium && is_clang) {
       # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
       suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
     }
+
+    if (!build_with_mozilla) {
+      deps += [
+        ":libjingle_peerconnection",
+      ]
+    }
   }
 }
--- a/media/webrtc/trunk/webrtc/base/BUILD.gn
+++ b/media/webrtc/trunk/webrtc/base/BUILD.gn
@@ -15,27 +15,32 @@ if (is_android) {
   import("//build/config/android/rules.gni")
 }
 if (is_win) {
   import("//build/config/clang/clang.gni")
 }
 
 group("base") {
   public_deps = [
-    ":rtc_base",
     ":rtc_base_approved",
     ":rtc_task_queue",
   ]
-  if (is_android) {
+  if (!build_with_mozilla) {
+    public_deps += [
+      ":rtc_base",
+    ]
+  }
+
+  if (is_android && !build_with_mozilla) {
     public_deps += [ ":base_java" ]
   }
 }
 
 config("rtc_base_approved_all_dependent_config") {
-  if (is_mac && !build_with_chromium) {
+  if (is_mac && !(build_with_chromium || build_with_mozilla)) {
     libs = [ "Foundation.framework" ]  # needed for logging_mac.mm
   }
 }
 
 config("rtc_base_config") {
   defines = [ "FEATURE_ENABLE_SSL" ]
 }
 
@@ -67,31 +72,33 @@ config("rtc_base_all_dependent_config") 
       "Foundation.framework",
       "IOKit.framework",
       "Security.framework",
       "SystemConfiguration.framework",
     ]
   }
 }
 
-if (is_linux && !build_with_chromium) {
+if (is_linux && !build_with_chromium && !build_with_mozilla) {
   # Provides the same functionality as the //crypto:platform target, which
   # WebRTC cannot use as we don't sync src/crypto from Chromium.
   group("linux_system_ssl") {
     deps = [
       "//third_party/boringssl",
     ]
   }
 }
 
 if (!rtc_build_ssl) {
   config("external_ssl_library") {
-    assert(rtc_ssl_root != "",
-           "You must specify rtc_ssl_root when rtc_build_ssl==0.")
-    include_dirs = [ rtc_ssl_root ]
+    if (!build_with_mozilla) {
+      assert(rtc_ssl_root != "",
+             "You must specify rtc_ssl_root when rtc_build_ssl==0.")
+      include_dirs = [ rtc_ssl_root ]
+    }
   }
 }
 
 # The subset of rtc_base approved for use outside of libjingle.
 rtc_static_library("rtc_base_approved") {
   defines = []
   libs = []
   deps = []
@@ -189,18 +196,29 @@ rtc_static_library("rtc_base_approved") 
   }
 
   if (is_posix) {
     sources += [ "file_posix.cc" ]
   }
 
   if (is_win) {
     sources += [ "file_win.cc" ]
+
+    if (build_with_mozilla) {
+      sources += [ "win32.cc" ]
+    }
   }
 
+  if (is_mac) {
+    if (build_with_mozilla) {
+      sources += [ "macutils.cc" ]
+    }
+  }
+
+
   if (build_with_chromium) {
     # Dependency on chromium's logging (in //base).
     deps += [ "//base:base" ]
     sources += [
       "../../webrtc_overrides/webrtc/base/logging.cc",
       "../../webrtc_overrides/webrtc/base/logging.h",
     ]
   } else {
@@ -318,16 +336,21 @@ rtc_static_library("rtc_task_queue") {
     }
 
     if (rtc_enable_libevent) {
       sources += [
         "task_queue_libevent.cc",
         "task_queue_posix.cc",
       ]
       all_dependent_configs = [ ":enable_libevent_config" ]
+
+      if (build_with_mozilla) {
+        include_dirs = [ "$rtc_libevent_dir/include" ]
+        include_dirs += [ "$rtc_libevent_dir/linux" ]
+      }
     } else {
       if (is_mac || is_ios) {
         sources += [
           "task_queue_gcd.cc",
           "task_queue_posix.cc",
         ]
       }
       if (is_win) {
@@ -938,17 +961,17 @@ if (rtc_include_tests) {
     configs += [ ":rtc_base_unittests_config" ]
     if (!build_with_chromium && is_clang) {
       # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
       suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
     }
   }
 }
 
-if (is_android) {
+if (is_android && !build_with_mozilla) {
   android_library("base_java") {
     java_files = [
       "java/src/org/webrtc/Logging.java",
       "java/src/org/webrtc/Size.java",
       "java/src/org/webrtc/ThreadUtils.java",
     ]
   }
 }
--- a/media/webrtc/trunk/webrtc/base/sigslot.h
+++ b/media/webrtc/trunk/webrtc/base/sigslot.h
@@ -2799,13 +2799,9 @@ namespace sigslot {
 				it = itNext;
 			}
 		}
 	};
 
 }; // namespace sigslot
 
 #endif // TALK_BASE_SIGSLOT_H__
-#endif // TALK_BASE_SIGSLOT_H__
-#endif // TALK_BASE_SIGSLOT_H__
-#endif // TALK_BASE_SIGSLOT_H__
-#endif // TALK_BASE_SIGSLOT_H__
 #endif // WEBRTC_BASE_SIGSLOT_H__
--- a/media/webrtc/trunk/webrtc/build/webrtc.gni
+++ b/media/webrtc/trunk/webrtc/build/webrtc.gni
@@ -6,17 +6,20 @@
 # in the file PATENTS.  All contributing project authors may
 # be found in the AUTHORS file in the root of the source tree.
 
 import("//build/config/arm.gni")
 import("//build/config/features.gni")
 import("//build/config/mips.gni")
 import("//build/config/sanitizers/sanitizers.gni")
 import("//build_overrides/build.gni")
-import("//testing/test.gni")
+
+if (!build_with_mozilla) {
+  import("//testing/test.gni")
+}
 
 declare_args() {
   # Disable this to avoid building the Opus audio codec.
   rtc_include_opus = true
 
   # Enable this to let the Opus audio codec change complexity on the fly.
   rtc_opus_variable_complexity = false
 
@@ -30,50 +33,47 @@ declare_args() {
   # Used to specify an external OpenSSL include path when not compiling the
   # library that comes with WebRTC (i.e. rtc_build_ssl == 0).
   rtc_ssl_root = ""
 
   # Selects fixed-point code where possible.
   rtc_prefer_fixed_point = false
 
   # Enables the use of protocol buffers for debug recordings.
-  rtc_enable_protobuf = true
+  rtc_enable_protobuf = !build_with_mozilla
 
   # Disable the code for the intelligibility enhancer by default.
   rtc_enable_intelligibility_enhancer = false
 
   # Enable when an external authentication mechanism is used for performing
   # packet authentication for RTP packets instead of libsrtp.
   rtc_enable_external_auth = build_with_chromium
 
   # Selects whether debug dumps for the audio processing module
   # should be generated.
   apm_debug_dump = false
 
   # Set this to true to enable BWE test logging.
   rtc_enable_bwe_test_logging = false
 
   # Set this to disable building with support for SCTP data channels.
-  rtc_enable_sctp = true
+  rtc_enable_sctp = !build_with_mozilla
 
   # Disable these to not build components which can be externally provided.
-  rtc_build_expat = true
-  rtc_build_json = true
-  rtc_build_libjpeg = true
-  rtc_build_libsrtp = true
-  rtc_build_libvpx = true
+  rtc_build_expat = !build_with_mozilla
+  rtc_build_json = !build_with_mozilla
+  rtc_build_libjpeg = !build_with_mozilla
+  rtc_build_libsrtp = !build_with_mozilla
+  rtc_build_libvpx = !build_with_mozilla
   rtc_libvpx_build_vp9 = true
-  rtc_build_libyuv = true
-  rtc_build_openmax_dl = true
-  rtc_build_opus = true
-  rtc_build_ssl = true
-  rtc_build_usrsctp = true
-
-  # Enable to use the Mozilla internal settings.
-  build_with_mozilla = false
+  rtc_build_libyuv = !build_with_mozilla
+  rtc_build_openmax_dl = !build_with_mozilla
+  rtc_build_opus = !build_with_mozilla
+  rtc_build_ssl = !build_with_mozilla
+  rtc_build_usrsctp = !build_with_mozilla
 
   rtc_enable_android_opensl = false
 
   # Link-Time Optimizations.
   # Executes code generation at link-time instead of compile-time.
   # https://gcc.gnu.org/wiki/LinkTimeOptimization
   rtc_use_lto = false
 
@@ -85,30 +85,34 @@ declare_args() {
   rtc_sanitize_coverage = ""
 
   # Enable libevent task queues on platforms that support it.
   if (is_win || is_mac || is_ios || is_nacl) {
     rtc_enable_libevent = false
     rtc_build_libevent = false
   } else {
     rtc_enable_libevent = true
-    rtc_build_libevent = true
+    rtc_build_libevent = !build_with_mozilla
   }
 
   if (current_cpu == "arm" || current_cpu == "arm64") {
     rtc_prefer_fixed_point = true
   }
 
   if (!is_ios && (current_cpu != "arm" || arm_version >= 7) &&
       current_cpu != "mips64el") {
     rtc_use_openmax_dl = true
   } else {
     rtc_use_openmax_dl = false
   }
 
+  if (build_with_mozilla) {
+    rtc_use_openmax_dl = false
+  }
+
   # Determines whether NEON code will be built.
   rtc_build_with_neon =
       (current_cpu == "arm" && arm_use_neon) || current_cpu == "arm64"
 
   # Enable this to build OpenH264 encoder/FFmpeg decoder. This is supported on
   # all platforms except Android and iOS. Because FFmpeg can be built
   # with/without H.264 support, |ffmpeg_branding| has to separately be set to a
   # value that includes H.264, for example "Chrome". If FFmpeg is built without
@@ -133,44 +137,49 @@ declare_args() {
   # by WebRTC during |H264DecoderImpl::InitDecode| or externally. FFmpeg must
   # only be initialized once. Projects that initialize FFmpeg externally, such
   # as Chromium, must turn this flag off so that WebRTC does not also
   # initialize.
   rtc_initialize_ffmpeg = !build_with_chromium
 
   # Build sources requiring GTK. NOTICE: This is not present in Chrome OS
   # build environments, even if available for Chromium builds.
-  rtc_use_gtk = !build_with_chromium
+  rtc_use_gtk = !build_with_chromium && !build_with_mozilla
 }
 
 # A second declare_args block, so that declarations within it can
 # depend on the possibly overridden variables in the first
 # declare_args block.
 declare_args() {
   # Include the iLBC audio codec?
   rtc_include_ilbc = !(build_with_chromium || build_with_mozilla)
 
-  rtc_restrict_logging = build_with_chromium
+  rtc_restrict_logging = build_with_chromium || build_with_mozilla
 
   # Excluded in Chromium since its prerequisites don't require Pulse Audio.
   rtc_include_pulse_audio = !build_with_chromium
 
   # Chromium uses its own IO handling, so the internal ADM is only built for
   # standalone WebRTC.
   rtc_include_internal_audio_device = !build_with_chromium
 
   # Include tests in standalone checkout.
-  rtc_include_tests = !build_with_chromium
+  rtc_include_tests = !build_with_chromium && !build_with_mozilla
 }
 
 # Make it possible to provide custom locations for some libraries (move these
 # up into declare_args should we need to actually use them for the GN build).
-rtc_libvpx_dir = "//third_party/libvpx"
-rtc_libyuv_dir = "//third_party/libyuv"
-rtc_opus_dir = "//third_party/opus"
+if (build_with_mozilla) {
+  rtc_libevent_dir = "/ipc/chromium/src/third_party/libevent"
+  rtc_libyuv_dir = "/media/libyuv/libyuv"
+} else {
+  rtc_libvpx_dir = "//third_party/libvpx"
+  rtc_libyuv_dir = "//third_party/libyuv"
+  rtc_opus_dir = "//third_party/opus"
+}
 
 ###############################################################################
 # Templates
 #
 
 # Points to //webrtc/ in webrtc stand-alone or to //third_party/webrtc/ in
 # chromium.
 # We need absolute paths for all configs in templates as they are shared in
--- a/media/webrtc/trunk/webrtc/call/BUILD.gn
+++ b/media/webrtc/trunk/webrtc/call/BUILD.gn
@@ -6,22 +6,31 @@
 # in the file PATENTS.  All contributing project authors may
 # be found in the AUTHORS file in the root of the source tree.
 
 import("../build/webrtc.gni")
 
 rtc_source_set("call_interfaces") {
   sources = [
     "audio_receive_stream.h",
-    "audio_send_stream.cc",
     "audio_send_stream.h",
     "audio_state.h",
     "call.h",
     "flexfec_receive_stream.h",
   ]
+
+  if (!build_with_mozilla) {
+    sources += [
+      "audio_send_stream.cc",
+    ]
+  } else {
+    sources += [
+      "audio_send_stream_call.cc",
+    ]
+  }
 }
 
 rtc_static_library("call") {
   sources = [
     "bitrate_allocator.cc",
     "call.cc",
     "flexfec_receive_stream_impl.cc",
     "flexfec_receive_stream_impl.h",
--- a/media/webrtc/trunk/webrtc/logging/BUILD.gn
+++ b/media/webrtc/trunk/webrtc/logging/BUILD.gn
@@ -2,17 +2,19 @@
 #
 # Use of this source code is governed by a BSD-style license
 # that can be found in the LICENSE file in the root of the source
 # tree. An additional intellectual property rights grant can be found
 # in the file PATENTS.  All contributing project authors may
 # be found in the AUTHORS file in the root of the source tree.
 
 import("../build/webrtc.gni")
-import("//third_party/protobuf/proto_library.gni")
+if (!build_with_mozilla) {
+  import("//third_party/protobuf/proto_library.gni")
+}
 if (is_android) {
   import("//build/config/android/config.gni")
   import("//build/config/android/rules.gni")
 }
 
 group("logging") {
   public_deps = [
     ":rtc_event_log_impl",
--- a/media/webrtc/trunk/webrtc/media/BUILD.gn
+++ b/media/webrtc/trunk/webrtc/media/BUILD.gn
@@ -5,20 +5,27 @@
 # tree. An additional intellectual property rights grant can be found
 # in the file PATENTS.  All contributing project authors may
 # be found in the AUTHORS file in the root of the source tree.
 
 import("//build/config/linux/pkg_config.gni")
 import("../build/webrtc.gni")
 
 group("media") {
-  public_deps = [
-    ":rtc_media",
-    ":rtc_media_base",
-  ]
+  public_deps = []
+  if (!build_with_mozilla) {
+    public_deps += [
+      ":rtc_media",
+      ":rtc_media_base",
+    ]
+  } else {
+    public_deps += [
+      ":mozilla_rtc_media",
+    ]
+  }
 }
 
 config("rtc_media_defines_config") {
   defines = [
     "HAVE_WEBRTC_VIDEO",
     "HAVE_WEBRTC_VOICE",
   ]
 }
@@ -37,16 +44,32 @@ if (is_linux && rtc_use_gtk) {
     packages = [
       "gobject-2.0",
       "gthread-2.0",
       "gtk+-2.0",
     ]
   }
 }
 
+if (build_with_mozilla) {
+  rtc_static_library("mozilla_rtc_media") {
+    defines = []
+    libs = []
+    deps = []
+    sources = [
+      "base/videoadapter.cc",
+      "base/videoadapter.h",
+      "base/videobroadcaster.cc",
+      "base/videobroadcaster.h",
+      "base/videosourcebase.cc",
+      "base/videosourcebase.h",
+    ]
+  }
+}
+
 rtc_static_library("rtc_media_base") {
   defines = []
   libs = []
   deps = []
   sources = [
     "base/adaptedvideotracksource.cc",
     "base/adaptedvideotracksource.h",
     "base/audiosource.h",
@@ -97,18 +120,23 @@ rtc_static_library("rtc_media_base") {
   } else {
     # Need to add a directory normally exported by libyuv.
     include_dirs += [ "$rtc_libyuv_dir/include" ]
   }
 
   deps += [
     "..:webrtc_common",
     "../base:rtc_base_approved",
-    "../p2p",
   ]
+
+  if (!build_with_mozilla) {
+    deps += [
+      "../p2p",
+    ]
+  }
 }
 
 rtc_static_library("rtc_media") {
   defines = []
   libs = []
   deps = []
   sources = [
     "engine/internaldecoderfactory.cc",
--- a/media/webrtc/trunk/webrtc/modules/BUILD.gn
+++ b/media/webrtc/trunk/webrtc/modules/BUILD.gn
@@ -18,26 +18,36 @@ group("modules") {
   public_deps = [
     "audio_coding",
     "audio_conference_mixer",
     "audio_device",
     "audio_mixer",
     "audio_processing",
     "bitrate_controller",
     "congestion_controller",
-    "desktop_capture",
     "media_file",
     "pacing",
     "remote_bitrate_estimator",
     "rtp_rtcp",
     "utility",
-    "video_capture",
     "video_coding",
     "video_processing",
   ]
+
+  if (!build_with_mozilla) {
+    public_deps += [
+      "video_capture",
+    ]
+  }
+
+  if (rtc_desktop_capture_supported) {
+    public_deps += [
+      "desktop_capture",
+    ]
+  }
 }
 
 if (rtc_include_tests) {
   modules_tests_resources = [
     "//resources/audio_coding/testfile32kHz.pcm",
     "//resources/audio_coding/teststereo32kHz.pcm",
     "//resources/foreman_cif.yuv",
     "//resources/paris_qcif.yuv",
@@ -61,29 +71,34 @@ if (rtc_include_tests) {
       videoprocessor_defines += [ "WEBRTC_VIDEOPROCESSOR_H264_TESTS" ]
     }
 
     defines = audio_coding_defines + videoprocessor_defines
 
     deps = [
       "..:webrtc_common",
       "../common_video",
-      "../media:rtc_media_base",
       "../modules/audio_coding",
       "../modules/audio_coding:audio_format_conversion",
       "../modules/rtp_rtcp",
       "../modules/utility",
       "../modules/video_coding",
       "../modules/video_coding:video_codecs_test_framework",
       "../system_wrappers",
       "../test:test_main",
       "//testing/gmock",
       "//testing/gtest",
     ]
 
+    if (!build_with_mozilla) {
+      deps += [
+        "../media:rtc_media_base",
+      ]
+    }
+
     sources = [
       "audio_coding/test/APITest.cc",
       "audio_coding/test/Channel.cc",
       "audio_coding/test/EncodeDecodeTest.cc",
       "audio_coding/test/PCMFile.cc",
       "audio_coding/test/PacketLossTest.cc",
       "audio_coding/test/RTPFile.cc",
       "audio_coding/test/TestAllCodecs.cc",
@@ -541,17 +556,17 @@ if (rtc_include_tests) {
       sources +=
           [ "video_coding/codecs/vp9/vp9_screenshare_layers_unittest.cc" ]
     }
 
     if (rtc_use_h264) {
       sources += [ "video_coding/codecs/h264/h264_encoder_impl_unittest.cc" ]
     }
 
-    if (rtc_desktop_capture_supported || is_android) {
+    if (rtc_desktop_capture_supported || (is_android && !build_with_mozilla)) {
       deps += [ "desktop_capture" ]
       sources += [
         "desktop_capture/desktop_region_unittest.cc",
         "desktop_capture/differ_block_unittest.cc",
       ]
     }
 
     if (rtc_desktop_capture_supported) {
@@ -643,17 +658,16 @@ if (rtc_include_tests) {
         "/wd4373",  # virtual function override.
       ]
     }
 
     deps += [
       ":audio_network_adaptor_unittests",
       "..:webrtc_common",
       "../api:transport_api",
-      "../base:rtc_base",  # TODO(kjellander): Cleanup in bugs.webrtc.org/3806.
       "../base:rtc_base_tests_utils",
       "../common_audio",
       "../common_video",
       "../system_wrappers",
       "../system_wrappers:metrics_default",
       "../test:rtp_test_utils",
       "../test:test_common",
       "../test:test_main",
@@ -688,16 +702,21 @@ if (rtc_include_tests) {
       "video_coding:webrtc_vp8",
       "video_coding:webrtc_vp9",
       "video_processing",
       "//testing/gmock",
       "//testing/gtest",
       "//third_party/gflags",
     ]
 
+    if (!build_with_mozilla) {
+      deps += [
+        "../base:rtc_base",  # TODO(kjellander): Cleanup in bugs.webrtc.org/3806.
+      ]
+    }
     data = modules_unittests_resources
 
     if (is_android) {
       deps += [
         "//testing/android/native_test:native_test_support",
         "//webrtc/sdk/android:libjingle_peerconnection_java",
       ]
 
--- a/media/webrtc/trunk/webrtc/modules/audio_coding/BUILD.gn
+++ b/media/webrtc/trunk/webrtc/modules/audio_coding/BUILD.gn
@@ -4,17 +4,19 @@
 # that can be found in the LICENSE file in the root of the source
 # tree. An additional intellectual property rights grant can be found
 # in the file PATENTS.  All contributing project authors may
 # be found in the AUTHORS file in the root of the source tree.
 
 import("../../build/webrtc.gni")
 import("audio_coding.gni")
 import("//build/config/arm.gni")
-import("//third_party/protobuf/proto_library.gni")
+if (!build_with_mozilla) {
+  import("//third_party/protobuf/proto_library.gni")
+}
 
 audio_codec_deps = [
   ":cng",
   ":g711",
   ":pcm16b",
 ]
 if (rtc_include_ilbc) {
   audio_codec_deps += [ ":ilbc" ]
@@ -23,18 +25,18 @@ if (rtc_include_opus) {
   audio_codec_deps += [ ":webrtc_opus" ]
 }
 if (!build_with_mozilla) {
   if (current_cpu == "arm") {
     audio_codec_deps += [ ":isac_fix" ]
   } else {
     audio_codec_deps += [ ":isac" ]
   }
-  audio_codec_deps += [ ":g722" ]
 }
+audio_codec_deps += [ ":g722" ]
 if (!build_with_mozilla && !build_with_chromium) {
   audio_codec_deps += [ ":red" ]
 }
 audio_coding_deps = audio_codec_deps + [
                       "../..:webrtc_common",
                       "../../common_audio",
                       "../../system_wrappers",
                     ]
@@ -868,17 +870,17 @@ rtc_source_set("webrtc_opus_c") {
     "codecs/opus/opus_interface.h",
   ]
 
   if (rtc_build_opus) {
     public_deps = [
       rtc_opus_dir,
     ]
   } else if (build_with_mozilla) {
-    include_dirs = [ getenv("DIST") + "/include/opus" ]
+    include_dirs = [ "/media/libopus/include" ]
   }
 
   deps = [
     "../..:webrtc_common",
     "../../base:rtc_base_approved",
   ]
 }
 
@@ -1046,19 +1048,19 @@ rtc_static_library("neteq") {
   if (!build_with_mozilla) {
     if (current_cpu == "arm") {
       defines += [ "WEBRTC_CODEC_ISACFX" ]
       deps += [ ":isac_fix" ]
     } else {
       defines += [ "WEBRTC_CODEC_ISAC" ]
       deps += [ ":isac" ]
     }
-    defines += [ "WEBRTC_CODEC_G722" ]
-    deps += [ ":g722" ]
   }
+  defines += [ "WEBRTC_CODEC_G722" ]
+  deps += [ ":g722" ]
 }
 
 # Although providing only test support, this target must be outside of the
 # rtc_include_tests conditional. The reason is that it supports fuzzer tests
 # that ultimately are built and run as a part of the Chromium ecosystem, which
 # does not set the rtc_include_tests flag.
 rtc_source_set("neteq_test_minimal") {
   testonly = true
--- a/media/webrtc/trunk/webrtc/modules/audio_coding/audio_coding.gni
+++ b/media/webrtc/trunk/webrtc/modules/audio_coding/audio_coding.gni
@@ -16,16 +16,16 @@ if (rtc_include_opus) {
   audio_codec_defines += [ "WEBRTC_CODEC_OPUS" ]
 }
 if (!build_with_mozilla) {
   if (current_cpu == "arm") {
     audio_codec_defines += [ "WEBRTC_CODEC_ISACFX" ]
   } else {
     audio_codec_defines += [ "WEBRTC_CODEC_ISAC" ]
   }
-  audio_codec_defines += [ "WEBRTC_CODEC_G722" ]
 }
+audio_codec_defines += [ "WEBRTC_CODEC_G722" ]
 if (!build_with_mozilla && !build_with_chromium) {
   audio_codec_defines += [ "WEBRTC_CODEC_RED" ]
 }
 
 audio_coding_defines = audio_codec_defines
 neteq_defines = audio_codec_defines
--- a/media/webrtc/trunk/webrtc/modules/audio_device/BUILD.gn
+++ b/media/webrtc/trunk/webrtc/modules/audio_device/BUILD.gn
@@ -76,16 +76,23 @@ rtc_static_library("audio_device") {
     "dummy/file_audio_device.cc",
     "dummy/file_audio_device.h",
     "fine_audio_buffer.cc",
     "fine_audio_buffer.h",
     "include/audio_device.h",
     "include/audio_device_defines.h",
   ]
 
+  if (build_with_mozilla) {
+    sources += [
+      "opensl/single_rw_fifo.cc",
+      "opensl/single_rw_fifo.h",
+    ]
+  }
+
   include_dirs = []
   if (is_linux) {
     include_dirs += [ "linux" ]
   }
   if (is_ios) {
     include_dirs += [ "ios" ]
   }
   if (is_mac) {
@@ -121,16 +128,24 @@ rtc_static_library("audio_device") {
         "android/opensles_player.h",
         "android/opensles_recorder.cc",
         "android/opensles_recorder.h",
       ]
       libs = [
         "log",
         "OpenSLES",
       ]
+
+      if (build_with_mozilla) {
+        include_dirs += [
+          "/config/external/nspr",
+          "/nsprpub/lib/ds",
+          "/nsprpub/pr/include",
+        ]
+      }
     }
     if (rtc_use_dummy_audio_file_devices) {
       defines += [ "WEBRTC_DUMMY_FILE_DEVICES" ]
     } else {
       if (is_linux) {
         sources += [
           "linux/alsasymboltable_linux.cc",
           "linux/alsasymboltable_linux.h",
--- a/media/webrtc/trunk/webrtc/modules/audio_processing/BUILD.gn
+++ b/media/webrtc/trunk/webrtc/modules/audio_processing/BUILD.gn
@@ -2,17 +2,19 @@
 #
 # Use of this source code is governed by a BSD-style license
 # that can be found in the LICENSE file in the root of the source
 # tree. An additional intellectual property rights grant can be found
 # in the file PATENTS.  All contributing project authors may
 # be found in the AUTHORS file in the root of the source tree.
 
 import("//build/config/arm.gni")
-import("//third_party/protobuf/proto_library.gni")
+if (!build_with_mozilla) {
+  import("//third_party/protobuf/proto_library.gni")
+}
 import("../../build/webrtc.gni")
 
 declare_args() {
   # Disables the usual mode where we trust the reported system delay
   # values the AEC receives. The corresponding define is set appropriately
   # in the code, but it can be force-enabled here for testing.
   aec_untrusted_delay_for_testing = false
 }
--- a/media/webrtc/trunk/webrtc/modules/congestion_controller/BUILD.gn
+++ b/media/webrtc/trunk/webrtc/modules/congestion_controller/BUILD.gn
@@ -39,19 +39,24 @@ rtc_static_library("congestion_controlle
 
   if (!build_with_chromium && is_clang) {
     # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
     suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
   }
 
   deps = [
     "../..:webrtc_common",
-    "../../base:rtc_base",
     "../../base:rtc_base_approved",
     "../../base:rtc_numerics",
     "../../system_wrappers",
     "../bitrate_controller",
     "../pacing",
     "../remote_bitrate_estimator",
     "../rtp_rtcp",
     "../utility",
   ]
+
+  if (!build_with_mozilla) {
+    deps += [
+      "../../base:rtc_base",
+    ]
+  }
 }
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/BUILD.gn
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/BUILD.gn
@@ -23,18 +23,23 @@ rtc_static_library("primitives") {
     "shared_desktop_frame.cc",
     "shared_desktop_frame.h",
     "shared_memory.cc",
     "shared_memory.h",
   ]
 
   deps = [
     "../..:webrtc_common",
-    "../../base:rtc_base",  # TODO(kjellander): Cleanup in bugs.webrtc.org/3806.
   ]
+
+  if (!build_with_mozilla) {
+    deps += [
+      "../../base:rtc_base",  # TODO(kjellander): Cleanup in bugs.webrtc.org/3806.
+    ]
+  }
 }
 
 if (rtc_include_tests) {
   source_set("rgba_color") {
     testonly = true
 
     public_deps = [
       ":desktop_capture",
@@ -170,28 +175,56 @@ rtc_static_library("desktop_capture") {
     "win/screen_capturer_win_magnifier.cc",
     "win/screen_capturer_win_magnifier.h",
     "win/window_capture_utils.cc",
     "win/window_capture_utils.h",
     "window_capturer_mac.mm",
     "window_capturer_win.cc",
   ]
 
+  if (build_with_mozilla) {
+    sources += [
+      "desktop_device_info.cc",
+      "desktop_device_info.h",
+      "app_capturer_win.cc",
+      "win/desktop_device_info_win.cc",
+      "win/win_shared.cc",
+    ]
+
+    if (is_mac) {
+      sources += [
+        "app_capturer_mac.mm",
+      ]
+    }
+  }
+
   if (use_x11) {
     sources += [
       "mouse_cursor_monitor_x11.cc",
       "screen_capturer_x11.cc",
       "window_capturer_x11.cc",
       "x11/shared_x_display.cc",
       "x11/shared_x_display.h",
       "x11/x_error_trap.cc",
       "x11/x_error_trap.h",
       "x11/x_server_pixel_buffer.cc",
       "x11/x_server_pixel_buffer.h",
     ]
+
+    if (build_with_mozilla) {
+      sources += [
+        "app_capturer_x11.cc",
+        "app_capturer_x11.h",
+        "x11/desktop_device_info_x11.cc",
+        "x11/desktop_device_info_x11.h",
+        "x11/shared_x_util.cc",
+        "x11/shared_x_util.h",
+      ]
+    }
+
     configs += [ "//build/config/linux:x11" ]
   }
 
   if (!is_win && !is_mac && !use_x11) {
     sources += [
       "mouse_cursor_monitor_null.cc",
       "screen_capturer_null.cc",
       "window_capturer_null.cc",
@@ -199,36 +232,56 @@ rtc_static_library("desktop_capture") {
   }
 
   if (is_mac) {
     libs = [
       "AppKit.framework",
       "IOKit.framework",
       "OpenGL.framework",
     ]
+
+    if (build_with_mozilla) {
+      sources += [
+        "mac/desktop_device_info_mac.mm",
+      ]
+    }
   }
 
   if (is_win) {
     libs = [
       "d3d11.lib",
       "dxgi.lib",
     ]
   }
 
   deps = [
     ":primitives",
     "../..:webrtc_common",
-    "../../base:rtc_base",  # TODO(kjellander): Cleanup in bugs.webrtc.org/3806.
     "../../system_wrappers",
-    "//third_party/libyuv",
   ]
 
+  if (!build_with_mozilla) {
+    deps += [
+      "../../base:rtc_base",  # TODO(kjellander): Cleanup in bugs.webrtc.org/3806.
+    ]
+  }
+
+  if (rtc_build_libyuv) {
+    deps += [ "$rtc_libyuv_dir" ]
+  } else {
+    include_dirs = [ "$rtc_libyuv_dir/include" ]
+  }
+
   if (use_desktop_capture_differ_sse2) {
     deps += [ ":desktop_capture_differ_sse2" ]
   }
+
+  if (build_with_mozilla) {
+    deps += ["../../base:rtc_base_approved"]
+  }
 }
 
 if (use_desktop_capture_differ_sse2) {
   # Have to be compiled as a separate target because it needs to be compiled
   # with SSE2 enabled.
   rtc_static_library("desktop_capture_differ_sse2") {
     visibility = [ ":*" ]
     sources = [
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/win/cursor.cc
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/win/cursor.cc
@@ -37,18 +37,16 @@ namespace {
 #define RGBA(r, g, b, a) \
     ((((r) << 24) & 0xff000000) | \
     (((g) << 16) & 0xff0000) | \
     (((b) << 8) & 0xff00) | \
     ((a) & 0xff))
 
 #endif  // !defined(WEBRTC_ARCH_LITTLE_ENDIAN)
 
-const int kBytesPerPixel = DesktopFrame::kBytesPerPixel;
-
 // Pixel colors used when generating cursor outlines.
 const uint32_t kPixelRgbaBlack = RGBA(0, 0, 0, 0xff);
 const uint32_t kPixelRgbaWhite = RGBA(0xff, 0xff, 0xff, 0xff);
 const uint32_t kPixelRgbaTransparent = RGBA(0, 0, 0, 0);
 
 const uint32_t kPixelRgbWhite = RGB(0xff, 0xff, 0xff);
 
 // Expands the cursor shape to add a white outline for visibility against
@@ -71,17 +69,17 @@ void AddCursorOutline(int width, int hei
       data++;
     }
   }
 }
 
 // Premultiplies RGB components of the pixel data in the given image by
 // the corresponding alpha components.
 void AlphaMul(uint32_t* data, int width, int height) {
-  static_assert(sizeof(uint32_t) == kBytesPerPixel,
+  static_assert(sizeof(uint32_t) == DesktopFrame::kBytesPerPixel,
                 "size of uint32 should be the number of bytes per pixel");
 
   for (uint32_t* data_end = data + width * height; data != data_end; ++data) {
     RGBQUAD* from = reinterpret_cast<RGBQUAD*>(data);
     RGBQUAD* to = reinterpret_cast<RGBQUAD*>(data);
     to->rgbBlue =
         (static_cast<uint16_t>(from->rgbBlue) * from->rgbReserved) / 0xff;
     to->rgbGreen =
@@ -139,17 +137,17 @@ MouseCursor* CreateMouseCursorFromHCurso
 
   // Get pixel data from |scoped_mask| converting it to 32bpp along the way.
   // GetDIBits() sets the alpha component of every pixel to 0.
   BITMAPV5HEADER bmi = {0};
   bmi.bV5Size = sizeof(bmi);
   bmi.bV5Width = width;
   bmi.bV5Height = -height;  // request a top-down bitmap.
   bmi.bV5Planes = 1;
-  bmi.bV5BitCount = kBytesPerPixel * 8;
+  bmi.bV5BitCount = DesktopFrame::kBytesPerPixel * 8;
   bmi.bV5Compression = BI_RGB;
   bmi.bV5AlphaMask = 0xff000000;
   bmi.bV5CSType = LCS_WINDOWS_COLOR_SPACE;
   bmi.bV5Intent = LCS_GM_BUSINESS;
   if (!GetDIBits(dc,
                  scoped_mask,
                  0,
                  height,
--- a/media/webrtc/trunk/webrtc/modules/remote_bitrate_estimator/BUILD.gn
+++ b/media/webrtc/trunk/webrtc/modules/remote_bitrate_estimator/BUILD.gn
@@ -46,20 +46,25 @@ rtc_static_library("remote_bitrate_estim
 
   if (!build_with_chromium && is_clang) {
     # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
     suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
   }
 
   deps = [
     "../..:webrtc_common",
-    "../../base:rtc_base",
     "../../base:rtc_base_approved",
     "../../system_wrappers",
   ]
+
+  if (!build_with_mozilla) {
+    deps += [
+      "../../base:rtc_base",
+    ]
+  }
 }
 
 if (rtc_include_tests) {
   rtc_static_library("bwe_simulator_lib") {
     testonly = true
     sources = [
       "test/bwe.cc",
       "test/bwe.h",
@@ -106,28 +111,33 @@ if (rtc_include_tests) {
         "/wd4373",  # virtual function override.
       ]
     }
 
     deps = [
       ":remote_bitrate_estimator",
       "../..:webrtc_common",
       "../../base:gtest_prod",
-      "../../base:rtc_base",
       "../../base:rtc_base_approved",
       "../../system_wrappers",
       "../../test:test_support",
       "../../voice_engine",
       "../bitrate_controller",
       "../congestion_controller",
       "../pacing",
       "../rtp_rtcp",
       "//testing/gmock",
       "//testing/gtest",
     ]
+
+    if (!build_with_mozilla) {
+      deps += [
+        "../../base:rtc_base",
+      ]
+    }
   }
 
   rtc_source_set("remote_bitrate_estimator_perf_tests") {
     testonly = true
     sources = [
       "remote_bitrate_estimators_test.cc",
     ]
     deps = [
--- a/media/webrtc/trunk/webrtc/modules/video_capture/BUILD.gn
+++ b/media/webrtc/trunk/webrtc/modules/video_capture/BUILD.gn
@@ -119,17 +119,26 @@ if (!build_with_chromium) {
         "windows/video_capture_ds.h",
         "windows/video_capture_factory_windows.cc",
         "windows/video_capture_mf.cc",
         "windows/video_capture_mf.h",
       ]
 
       libs = [ "Strmiids.lib" ]
 
-      deps += [ "//third_party/winsdk_samples" ]
+      if (!build_with_mozilla) {
+        deps += [ "//third_party/winsdk_samples" ]
+      } else {
+        sources += [
+          "windows/BasePin.cpp",
+          "windows/BaseFilter.cpp",
+          "windows/BaseInputPin.cpp",
+          "windows/MediaType.cpp",
+        ]
+      }
     }
     if (is_ios || is_mac) {
       sources = [
         "objc/device_info.h",
         "objc/device_info.mm",
         "objc/device_info_objc.h",
         "objc/device_info_objc.mm",
         "objc/rtc_video_capture_objc.h",
@@ -143,16 +152,29 @@ if (!build_with_chromium) {
 
         # To avoid warnings for deprecated videoMinFrameDuration and
         # videoMaxFrameDuration properties in iOS 7.0.
         # See webrtc:3705 for more details.
         "-Wno-deprecated-declarations",
       ]
     }
 
+    if (build_with_mozilla && is_android) {
+      include_dirs = [
+        "/config/external/nspr",
+        "/nsprpub/lib/ds",
+        "/nsprpub/pr/include",
+      ]
+
+      sources = [
+        "android/device_info_android.cc",
+        "android/video_capture_android.cc",
+      ]
+    }
+
     all_dependent_configs = [ ":video_capture_internal_impl_config" ]
 
     if (!build_with_chromium && is_clang) {
       # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
       suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
     }
   }
 
--- a/media/webrtc/trunk/webrtc/modules/video_coding/BUILD.gn
+++ b/media/webrtc/trunk/webrtc/modules/video_coding/BUILD.gn
@@ -88,25 +88,30 @@ rtc_static_library("video_coding") {
 
   deps = [
     ":video_coding_utility",
     ":webrtc_h264",
     ":webrtc_i420",
     ":webrtc_vp8",
     ":webrtc_vp9",
     "../..:webrtc_common",
-    "../../base:rtc_base",
     "../../base:rtc_base_approved",
     "../../base:rtc_numerics",
     "../../base:rtc_task_queue",
     "../../common_video",
     "../../system_wrappers",
     "../rtp_rtcp:rtp_rtcp",
     "../utility:utility",
   ]
+
+  if (!build_with_mozilla) {
+    deps += [
+      "../../base:rtc_base",
+    ]
+  }
 }
 
 rtc_static_library("video_coding_utility") {
   # TODO(ehmaldonado): Remove (bugs.webrtc.org/6828)
   # Errors on cyclic dependency with :video_coding if enabled.
   check_includes = false
 
   sources = [
@@ -178,20 +183,25 @@ rtc_static_library("webrtc_h264") {
     sources += [
       "codecs/h264/h264_decoder_impl.cc",
       "codecs/h264/h264_decoder_impl.h",
       "codecs/h264/h264_encoder_impl.cc",
       "codecs/h264/h264_encoder_impl.h",
     ]
     deps += [
       "../../common_video",
-      "../../media:rtc_media_base",
       "//third_party/ffmpeg:ffmpeg",
       "//third_party/openh264:encoder",
     ]
+
+    if (!build_with_mozilla) {
+      deps += [
+        "../../media:rtc_media_base",
+      ]
+    }
   }
 }
 
 rtc_static_library("webrtc_i420") {
   sources = [
     "codecs/i420/i420.cc",
     "codecs/i420/include/i420.h",
   ]
@@ -240,16 +250,20 @@ rtc_static_library("webrtc_vp8") {
     "../..:webrtc_common",
     "../../base:rtc_base_approved",
     "../../common_video",
     "../../system_wrappers",
   ]
   if (rtc_build_libvpx) {
     deps += [ rtc_libvpx_dir ]
   }
+
+  if (build_with_mozilla) {
+    include_dirs = [ "$rtc_libyuv_dir/include" ]
+  }
 }
 
 rtc_static_library("webrtc_vp9") {
   if (rtc_libvpx_build_vp9) {
     sources = [
       "codecs/vp9/include/vp9.h",
       "codecs/vp9/screenshare_layers.cc",
       "codecs/vp9/screenshare_layers.h",
--- a/media/webrtc/trunk/webrtc/modules/video_processing/BUILD.gn
+++ b/media/webrtc/trunk/webrtc/modules/video_processing/BUILD.gn
@@ -38,16 +38,20 @@ rtc_static_library("video_processing") {
   if (rtc_build_with_neon) {
     deps += [ ":video_processing_neon" ]
   }
 
   if (!build_with_chromium && is_clang) {
     # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
     suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
   }
+
+  if (build_with_mozilla) {
+    include_dirs = [ "$rtc_libyuv_dir/include" ]
+  }
 }
 
 if (build_video_processing_sse2) {
   rtc_static_library("video_processing_sse2") {
     # TODO(mbonadei): Remove (bugs.webrtc.org/6828)
     # Errors on cyclic dependency with :video_processing if enabled.
     check_includes = false
 
--- a/media/webrtc/trunk/webrtc/system_wrappers/BUILD.gn
+++ b/media/webrtc/trunk/webrtc/system_wrappers/BUILD.gn
@@ -77,17 +77,25 @@ rtc_static_library("system_wrappers") {
   if (is_android) {
     sources += [
       "include/logcat_trace_context.h",
       "source/logcat_trace_context.cc",
     ]
 
     defines += [ "WEBRTC_THREAD_RR" ]
 
-    deps += [ ":cpu_features_android" ]
+    if (!build_with_mozilla) {
+      deps += [ ":cpu_features_android" ]
+    } else {
+      include_dirs = [
+        "/config/external/nspr",
+        "/nsprpub/lib/ds",
+        "/nsprpub/pr/include",
+      ]
+    }
 
     libs += [ "log" ]
   }
 
   if (is_linux) {
     defines += [ "WEBRTC_THREAD_RR" ]
 
     if (!build_with_chromium) {
@@ -140,17 +148,17 @@ rtc_static_library("metrics_default") {
 group("system_wrappers_default") {
   deps = [
     ":field_trial_default",
     ":metrics_default",
     ":system_wrappers",
   ]
 }
 
-if (is_android) {
+if (is_android && !build_with_mozilla) {
   rtc_static_library("cpu_features_android") {
     sources = [
       "source/cpu_features_android.c",
     ]
 
     deps = [
       "//third_party/android_tools:cpu_features",
     ]
--- a/media/webrtc/trunk/webrtc/video/BUILD.gn
+++ b/media/webrtc/trunk/webrtc/video/BUILD.gn
@@ -58,51 +58,60 @@ rtc_static_library("video") {
   deps = [
     "..:webrtc_common",
     "../api:transport_api",
     "../base:rtc_base_approved",
     "../base:rtc_numerics",
     "../base:rtc_task_queue",
     "../common_video",
     "../logging:rtc_event_log_api",
-    "../media:rtc_media_base",
     "../modules/bitrate_controller",
     "../modules/congestion_controller",
     "../modules/pacing",
     "../modules/remote_bitrate_estimator",
     "../modules/rtp_rtcp",
     "../modules/utility",
     "../modules/video_coding",
     "../modules/video_processing",
     "../system_wrappers",
     "../voice_engine",
   ]
+
+  if (!build_with_mozilla) {
+    deps += [
+      "../media:rtc_media_base",
+    ]
+  }
 }
 
 if (rtc_include_tests) {
   rtc_source_set("video_quality_test") {
     testonly = true
     sources = [
       "video_quality_test.cc",
       "video_quality_test.h",
     ]
     deps = [
       "../base:rtc_task_queue",
-      "../media:rtc_media_base",
       "../system_wrappers",
       "//testing/gtest",
       "//webrtc/test:test_renderer",
     ]
     if (!is_android) {
       deps += [ "../modules/video_capture:video_capture_internal_impl" ]
     }
     if (!build_with_chromium && is_clang) {
       # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
       suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
     }
+    if (!build_with_mozilla) {
+      deps += [
+        "../media:rtc_media_base",
+      ]
+    }
   }
 
   rtc_source_set("video_full_stack_tests") {
     testonly = true
     sources = [
       "full_stack_tests.cc",
     ]
     deps = [
@@ -203,21 +212,25 @@ if (rtc_include_tests) {
       "stats_counter_unittest.cc",
       "stream_synchronization_unittest.cc",
       "video_send_stream_tests.cc",
       "vie_encoder_unittest.cc",
       "vie_remb_unittest.cc",
     ]
     deps = [
       ":video",
-      "../media:rtc_media_base",
       "//testing/gmock",
       "//testing/gtest",
     ]
     if (!build_with_chromium && is_clang) {
       # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
       suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
     }
     if (rtc_use_h264) {
       defines += [ "WEBRTC_USE_H264" ]
     }
+    if (!build_with_mozilla) {
+      deps += [
+        "../media:rtc_media_base",
+      ]
+    }
   }
 }
new file mode 100644
--- /dev/null
+++ b/media/webrtc/trunk/webrtc/video_engine/BUILD.gn
@@ -0,0 +1,12 @@
+import("../build/webrtc.gni")
+
+rtc_static_library("video_engine") {
+  sources = [
+    "browser_capture_impl.h",
+    "desktop_capture_impl.cc",
+    "desktop_capture_impl.h",
+  ]
+  deps = [
+    "..:webrtc_common",
+  ]
+}