Move the below build targets to api/video:

- adapted_video_track_source
- video_adapter
- video_broadcaster
- video_common

These targets are meant to replace rtc_media_base.

Change-Id: Iaa69cd8379f66f98d618ac2e4fb6ffb4a1806f50
Bug: webrtc:42225070
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/483960
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Jeremy Leconte <jleconte@google.com>
Cr-Commit-Position: refs/heads/main@{#48064}
diff --git a/api/BUILD.gn b/api/BUILD.gn
index 0b3de97..2030900 100644
--- a/api/BUILD.gn
+++ b/api/BUILD.gn
@@ -1819,6 +1819,9 @@
       "units:units_unittests",
       "video:frame_buffer_unittest",
       "video:rtp_video_frame_assembler_unittests",
+      "video:video_adapter_unittest",
+      "video:video_broadcaster_unittest",
+      "video:video_common_unittest",
       "video:video_frame",
       "video:video_frame_metadata_unittest",
       "video/corruption_detection:corruption_detection_unittests",
diff --git a/api/video/BUILD.gn b/api/video/BUILD.gn
index f8b8c22..980cdcb 100644
--- a/api/video/BUILD.gn
+++ b/api/video/BUILD.gn
@@ -413,3 +413,129 @@
     "../../test:test_support",
   ]
 }
+
+rtc_library("video_common") {
+  visibility = [ "*" ]
+  sources = [
+    "video_common.cc",
+    "video_common.h",
+  ]
+  deps = [
+    "../../rtc_base:stringutils",
+    "../../rtc_base:timeutils",
+    "../../rtc_base/system:rtc_export",
+  ]
+}
+
+rtc_library("video_adapter") {
+  visibility = [ "*" ]
+  sources = [
+    "video_adapter.cc",
+    "video_adapter.h",
+  ]
+  deps = [
+    ":resolution",
+    ":video_common",
+    ":video_frame",
+    "../../common_video",
+    "../../rtc_base:checks",
+    "../../rtc_base:logging",
+    "../../rtc_base:macromagic",
+    "../../rtc_base:stringutils",
+    "../../rtc_base:timeutils",
+    "../../rtc_base/synchronization:mutex",
+    "../../rtc_base/system:rtc_export",
+  ]
+}
+
+rtc_library("video_broadcaster") {
+  visibility = [ "*" ]
+  sources = [
+    "video_broadcaster.cc",
+    "video_broadcaster.h",
+  ]
+  deps = [
+    ":video_common",
+    ":video_frame",
+    ":video_rtp_headers",
+    "..:media_stream_interface",
+    "..:scoped_refptr",
+    "..:sequence_checker",
+    "..:video_track_source_constraints",
+    "../../media:video_source_base",
+    "../../rtc_base:checks",
+    "../../rtc_base:logging",
+    "../../rtc_base:macromagic",
+    "../../rtc_base/synchronization:mutex",
+  ]
+}
+
+rtc_library("adapted_video_track_source") {
+  visibility = [ "*" ]
+  sources = [
+    "adapted_video_track_source.cc",
+    "adapted_video_track_source.h",
+  ]
+  deps = [
+    ":recordable_encoded_frame",
+    ":video_adapter",
+    ":video_broadcaster",
+    ":video_frame",
+    ":video_rtp_headers",
+    "..:media_stream_interface",
+    "..:scoped_refptr",
+    "..:video_track_source_constraints",
+    "../../rtc_base:checks",
+    "../../rtc_base:macromagic",
+    "../../rtc_base:timeutils",
+    "../../rtc_base/synchronization:mutex",
+    "../../rtc_base/system:rtc_export",
+  ]
+}
+
+if (rtc_include_tests) {
+  rtc_library("video_common_unittest") {
+    testonly = true
+    sources = [ "video_common_unittest.cc" ]
+    deps = [
+      ":video_common",
+      "../../rtc_base:timeutils",
+      "../../test:test_support",
+    ]
+  }
+
+  rtc_library("video_adapter_unittest") {
+    testonly = true
+    sources = [ "video_adapter_unittest.cc" ]
+    deps = [
+      ":resolution",
+      ":video_adapter",
+      ":video_common",
+      ":video_frame",
+      "..:field_trials",
+      "../../media:rtc_media_tests_utils",
+      "../../rtc_base:timeutils",
+      "../../test:create_test_field_trials",
+      "../../test:test_support",
+      "../units:time_delta",
+      "../units:timestamp",
+      "//third_party/abseil-cpp/absl/strings",
+    ]
+  }
+
+  rtc_library("video_broadcaster_unittest") {
+    testonly = true
+    sources = [ "video_broadcaster_unittest.cc" ]
+    deps = [
+      ":video_broadcaster",
+      ":video_frame",
+      ":video_rtp_headers",
+      "..:scoped_refptr",
+      "..:video_track_source_constraints",
+      "../../media:rtc_media_tests_utils",
+      "../../rtc_base:checks",
+      "../../test:test_support",
+      "../units:time_delta",
+    ]
+  }
+}
diff --git a/api/video/DEPS b/api/video/DEPS
index 741e79a..72385a0 100644
--- a/api/video/DEPS
+++ b/api/video/DEPS
@@ -74,4 +74,21 @@
   "video_frame_matchers\\.h": [
     "+test/gmock.h",
   ],
+  "adapted_video_track_source\\.h" : [
+    "+rtc_base/synchronization/mutex.h",
+    "+rtc_base/thread_annotations.h",
+  ],
+  "video_adapter\\.h" : [
+    "+common_video/framerate_controller.h",
+    "+rtc_base/synchronization/mutex.h",
+    "+rtc_base/thread_annotations.h",
+  ],
+  "video_broadcaster\\.h" : [
+    "+media/base/video_source_base.h",
+    "+rtc_base/synchronization/mutex.h",
+    "+rtc_base/thread_annotations.h",
+  ],
+  "video_common\\.h" : [
+    "+rtc_base/time_utils.h",
+  ],
 }
diff --git a/media/base/adapted_video_track_source.cc b/api/video/adapted_video_track_source.cc
similarity index 98%
rename from media/base/adapted_video_track_source.cc
rename to api/video/adapted_video_track_source.cc
index d65dd5b..afaa55e 100644
--- a/media/base/adapted_video_track_source.cc
+++ b/api/video/adapted_video_track_source.cc
@@ -8,7 +8,7 @@
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
-#include "media/base/adapted_video_track_source.h"
+#include "api/video/adapted_video_track_source.h"
 
 #include <cstdint>
 
diff --git a/api/video/adapted_video_track_source.h b/api/video/adapted_video_track_source.h
new file mode 100644
index 0000000..f498ac3
--- /dev/null
+++ b/api/video/adapted_video_track_source.h
@@ -0,0 +1,107 @@
+/*
+ *  Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ *  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.
+ */
+
+#ifndef API_VIDEO_ADAPTED_VIDEO_TRACK_SOURCE_H_
+#define API_VIDEO_ADAPTED_VIDEO_TRACK_SOURCE_H_
+
+#include <stdint.h>
+
+#include <optional>
+
+#include "api/media_stream_interface.h"
+#include "api/notifier.h"
+#include "api/video/recordable_encoded_frame.h"
+#include "api/video/video_adapter.h"
+#include "api/video/video_broadcaster.h"
+#include "api/video/video_frame.h"
+#include "api/video/video_sink_interface.h"
+#include "api/video/video_source_interface.h"
+#include "api/video_track_source_constraints.h"
+#include "rtc_base/synchronization/mutex.h"
+#include "rtc_base/system/rtc_export.h"
+#include "rtc_base/thread_annotations.h"
+
+namespace webrtc {
+
+// Base class for sources which needs video adaptation, e.g., video
+// capture sources. Sinks must be added and removed on one and only
+// one thread, while AdaptFrame and OnFrame may be called on any
+// thread.
+class RTC_EXPORT AdaptedVideoTrackSource
+    : public Notifier<VideoTrackSourceInterface> {
+ public:
+  AdaptedVideoTrackSource();
+  ~AdaptedVideoTrackSource() override;
+
+ protected:
+  // Allows derived classes to initialize `video_adapter_` with a custom
+  // alignment.
+  explicit AdaptedVideoTrackSource(int required_alignment);
+  // Checks the apply_rotation() flag. If the frame needs rotation, and it is a
+  // plain memory frame, it is rotated. Subclasses producing native frames must
+  // handle apply_rotation() themselves.
+  void OnFrame(const VideoFrame& frame);
+  // Indication from source that a frame was dropped.
+  void OnFrameDropped();
+
+  // Reports the appropriate frame size after adaptation. Returns true
+  // if a frame is wanted. Returns false if there are no interested
+  // sinks, or if the VideoAdapter decides to drop the frame.
+  bool AdaptFrame(int width,
+                  int height,
+                  int64_t time_us,
+                  int* out_width,
+                  int* out_height,
+                  int* crop_width,
+                  int* crop_height,
+                  int* crop_x,
+                  int* crop_y);
+
+  // Returns the current value of the apply_rotation flag, derived
+  // from the VideoSinkWants of registered sinks. The value is derived
+  // from sinks' wants, in AddOrUpdateSink and RemoveSink. Beware that
+  // when using this method from a different thread, the value may
+  // become stale before it is used.
+  bool apply_rotation();
+
+  VideoAdapter* video_adapter() { return &video_adapter_; }
+
+ private:
+  // Implements VideoSourceInterface.
+  void AddOrUpdateSink(VideoSinkInterface<VideoFrame>* sink,
+                       const VideoSinkWants& wants) override;
+  void RemoveSink(VideoSinkInterface<VideoFrame>* sink) override;
+
+  // Part of VideoTrackSourceInterface.
+  bool GetStats(Stats* stats) override;
+
+  void OnSinkWantsChanged(const VideoSinkWants& wants);
+
+  // Encoded sinks not implemented for AdaptedVideoTrackSource.
+  bool SupportsEncodedOutput() const override { return false; }
+  void GenerateKeyFrame() override {}
+  void AddEncodedSink(
+      VideoSinkInterface<RecordableEncodedFrame>* /* sink */) override {}
+  void RemoveEncodedSink(
+      VideoSinkInterface<RecordableEncodedFrame>* /* sink */) override {}
+  void ProcessConstraints(
+      const VideoTrackSourceConstraints& constraints) override;
+
+  VideoAdapter video_adapter_;
+
+  Mutex stats_mutex_;
+  std::optional<Stats> stats_ RTC_GUARDED_BY(stats_mutex_);
+
+  VideoBroadcaster broadcaster_;
+};
+
+}  //  namespace webrtc
+
+#endif  // API_VIDEO_ADAPTED_VIDEO_TRACK_SOURCE_H_
diff --git a/media/base/video_adapter.cc b/api/video/video_adapter.cc
similarity index 99%
rename from media/base/video_adapter.cc
rename to api/video/video_adapter.cc
index 533bb95..4fc21f9 100644
--- a/media/base/video_adapter.cc
+++ b/api/video/video_adapter.cc
@@ -8,7 +8,7 @@
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
-#include "media/base/video_adapter.h"
+#include "api/video/video_adapter.h"
 
 #include <algorithm>
 #include <cmath>
@@ -21,8 +21,8 @@
 #include <utility>
 
 #include "api/video/resolution.h"
+#include "api/video/video_common.h"
 #include "api/video/video_source_interface.h"
-#include "media/base/video_common.h"
 #include "rtc_base/checks.h"
 #include "rtc_base/logging.h"
 #include "rtc_base/strings/string_builder.h"
diff --git a/api/video/video_adapter.h b/api/video/video_adapter.h
new file mode 100644
index 0000000..c25bbe7
--- /dev/null
+++ b/api/video/video_adapter.h
@@ -0,0 +1,172 @@
+/*
+ *  Copyright (c) 2010 The WebRTC project authors. All Rights Reserved.
+ *
+ *  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.
+ */
+
+#ifndef API_VIDEO_VIDEO_ADAPTER_H_
+#define API_VIDEO_VIDEO_ADAPTER_H_
+
+#include <stdint.h>
+
+#include <optional>
+#include <string>
+#include <utility>
+
+#include "api/video/resolution.h"
+#include "api/video/video_common.h"
+#include "api/video/video_source_interface.h"
+#include "common_video/framerate_controller.h"
+#include "rtc_base/synchronization/mutex.h"
+#include "rtc_base/system/rtc_export.h"
+#include "rtc_base/thread_annotations.h"
+
+namespace webrtc {
+
+// VideoAdapter adapts an input video frame to an output frame based on the
+// specified input and output formats. The adaptation includes dropping frames
+// to reduce frame rate and scaling frames.
+// VideoAdapter is thread safe.
+class RTC_EXPORT VideoAdapter {
+ public:
+  VideoAdapter();
+  // The source requests output frames whose width and height are divisible
+  // by `source_resolution_alignment`.
+  explicit VideoAdapter(int source_resolution_alignment);
+  virtual ~VideoAdapter();
+
+  VideoAdapter(const VideoAdapter&) = delete;
+  VideoAdapter& operator=(const VideoAdapter&) = delete;
+
+  // Return the adapted resolution and cropping parameters given the
+  // input resolution. The input frame should first be cropped, then
+  // scaled to the final output resolution. Returns true if the frame
+  // should be adapted, and false if it should be dropped.
+  bool AdaptFrameResolution(int in_width,
+                            int in_height,
+                            int64_t in_timestamp_ns,
+                            int* cropped_width,
+                            int* cropped_height,
+                            int* out_width,
+                            int* out_height) RTC_LOCKS_EXCLUDED(mutex_);
+
+  // DEPRECATED. Please use OnOutputFormatRequest below.
+  // TODO(asapersson): Remove this once it is no longer used.
+  // Requests the output frame size and frame interval from
+  // `AdaptFrameResolution` to not be larger than `format`. Also, the input
+  // frame size will be cropped to match the requested aspect ratio. The
+  // requested aspect ratio is orientation agnostic and will be adjusted to
+  // maintain the input orientation, so it doesn't matter if e.g. 1280x720 or
+  // 720x1280 is requested.
+  // Note: Should be called from the source only.
+  void OnOutputFormatRequest(const std::optional<VideoFormat>& format)
+      RTC_LOCKS_EXCLUDED(mutex_);
+
+  // Requests output frame size and frame interval from `AdaptFrameResolution`.
+  // `target_aspect_ratio`: The input frame size will be cropped to match the
+  // requested aspect ratio. The aspect ratio is orientation agnostic and will
+  // be adjusted to maintain the input orientation (i.e. it doesn't matter if
+  // e.g. <1280,720> or <720,1280> is requested).
+  // `max_pixel_count`: The maximum output frame size.
+  // `max_fps`: The maximum output framerate.
+  // Note: Should be called from the source only.
+  void OnOutputFormatRequest(
+      const std::optional<std::pair<int, int>>& target_aspect_ratio,
+      const std::optional<int>& max_pixel_count,
+      const std::optional<int>& max_fps) RTC_LOCKS_EXCLUDED(mutex_);
+
+  // Same as above, but allows setting two different target aspect ratios
+  // depending on incoming frame orientation. This gives more fine-grained
+  // control and can e.g. be used to force landscape video to be cropped to
+  // portrait video.
+  void OnOutputFormatRequest(
+      const std::optional<std::pair<int, int>>& target_landscape_aspect_ratio,
+      const std::optional<int>& max_landscape_pixel_count,
+      const std::optional<std::pair<int, int>>& target_portrait_aspect_ratio,
+      const std::optional<int>& max_portrait_pixel_count,
+      const std::optional<int>& max_fps) RTC_LOCKS_EXCLUDED(mutex_);
+
+  // Requests the output frame size from `AdaptFrameResolution` to have as close
+  // as possible to `sink_wants.target_pixel_count` pixels (if set)
+  // but no more than `sink_wants.max_pixel_count`.
+  // `sink_wants.max_framerate_fps` is essentially analogous to
+  // `sink_wants.max_pixel_count`, but for framerate rather than resolution.
+  // Set `sink_wants.max_pixel_count` and/or `sink_wants.max_framerate_fps` to
+  // std::numeric_limit<int>::max() if no upper limit is desired.
+  // The sink resolution alignment requirement is given by
+  // `sink_wants.resolution_alignment`.
+  // Note: Should be called from the sink only.
+  void OnSinkWants(const VideoSinkWants& sink_wants) RTC_LOCKS_EXCLUDED(mutex_);
+
+  // Returns maximum image area, which shouldn't impose any adaptations.
+  // Can return `numeric_limits<int>::max()` if no limit is set.
+  int GetTargetPixels() const;
+
+  // Returns current frame-rate limit.
+  // Can return `numeric_limits<float>::infinity()` if no limit is set.
+  float GetMaxFramerate() const;
+
+ private:
+  // Determine if frame should be dropped based on input fps and requested fps.
+  bool DropFrame(int64_t in_timestamp_ns) RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+
+  int frames_in_ RTC_GUARDED_BY(mutex_);      // Number of input frames.
+  int frames_out_ RTC_GUARDED_BY(mutex_);     // Number of output frames.
+  int frames_scaled_ RTC_GUARDED_BY(mutex_);  // Number of frames scaled.
+  int adaption_changes_
+      RTC_GUARDED_BY(mutex_);  // Number of changes in scale factor.
+  int previous_width_ RTC_GUARDED_BY(mutex_);  // Previous adapter output width.
+  int previous_height_
+      RTC_GUARDED_BY(mutex_);  // Previous adapter output height.
+
+  // The fixed source resolution alignment requirement.
+  const int source_resolution_alignment_;
+  // The currently applied resolution alignment, as given by the requirements:
+  //  - the fixed `source_resolution_alignment_`; and
+  //  - the latest `sink_wants.resolution_alignment`.
+  int resolution_alignment_ RTC_GUARDED_BY(mutex_);
+
+  // Max number of pixels/fps requested via calls to OnOutputFormatRequest,
+  // OnResolutionFramerateRequest respectively.
+  // The adapted output format is the minimum of these.
+  struct OutputFormatRequest {
+    std::optional<std::pair<int, int>> target_landscape_aspect_ratio;
+    std::optional<int> max_landscape_pixel_count;
+    std::optional<std::pair<int, int>> target_portrait_aspect_ratio;
+    std::optional<int> max_portrait_pixel_count;
+    std::optional<int> max_fps;
+
+    // For logging.
+    std::string ToString() const;
+  };
+
+  OutputFormatRequest output_format_request_ RTC_GUARDED_BY(mutex_);
+  int resolution_request_target_pixel_count_ RTC_GUARDED_BY(mutex_);
+  int resolution_request_max_pixel_count_ RTC_GUARDED_BY(mutex_);
+  int max_framerate_request_ RTC_GUARDED_BY(mutex_);
+  std::optional<Resolution> scale_resolution_down_to_ RTC_GUARDED_BY(mutex_);
+
+  // Stashed OutputFormatRequest that is used to save value of
+  // OnOutputFormatRequest in case all active encoders are using
+  // scale_resolution_down_to. I.e when all active encoders are using
+  // scale_resolution_down_to, the call to OnOutputFormatRequest is ignored
+  // and the value from scale_resolution_down_to is used instead (to scale/crop
+  // frame). This allows for an application to only use
+  // RtpEncodingParameters::request_resolution and get the same behavior as if
+  // it had used VideoAdapter::OnOutputFormatRequest.
+  std::optional<OutputFormatRequest> stashed_output_format_request_
+      RTC_GUARDED_BY(mutex_);
+
+  FramerateController framerate_controller_ RTC_GUARDED_BY(mutex_);
+
+  // The critical section to protect the above variables.
+  mutable Mutex mutex_;
+};
+
+}  //  namespace webrtc
+
+#endif  // API_VIDEO_VIDEO_ADAPTER_H_
diff --git a/media/base/video_adapter_unittest.cc b/api/video/video_adapter_unittest.cc
similarity index 99%
rename from media/base/video_adapter_unittest.cc
rename to api/video/video_adapter_unittest.cc
index 1c74129..c0a1f83 100644
--- a/media/base/video_adapter_unittest.cc
+++ b/api/video/video_adapter_unittest.cc
@@ -8,7 +8,7 @@
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
-#include "media/base/video_adapter.h"
+#include "api/video/video_adapter.h"
 
 #include <cstddef>
 #include <cstdint>
@@ -22,10 +22,10 @@
 #include "api/units/time_delta.h"
 #include "api/units/timestamp.h"
 #include "api/video/resolution.h"
+#include "api/video/video_common.h"
 #include "api/video/video_frame.h"
 #include "api/video/video_source_interface.h"
 #include "media/base/fake_frame_source.h"
-#include "media/base/video_common.h"
 #include "rtc_base/time_utils.h"
 #include "test/create_test_field_trials.h"
 #include "test/gmock.h"
diff --git a/media/base/video_broadcaster.cc b/api/video/video_broadcaster.cc
similarity index 99%
rename from media/base/video_broadcaster.cc
rename to api/video/video_broadcaster.cc
index ac26324..15c4af5 100644
--- a/media/base/video_broadcaster.cc
+++ b/api/video/video_broadcaster.cc
@@ -8,7 +8,7 @@
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
-#include "media/base/video_broadcaster.h"
+#include "api/video/video_broadcaster.h"
 
 #include <algorithm>
 #include <numeric>
diff --git a/api/video/video_broadcaster.h b/api/video/video_broadcaster.h
new file mode 100644
index 0000000..d0e6a10
--- /dev/null
+++ b/api/video/video_broadcaster.h
@@ -0,0 +1,84 @@
+/*
+ *  Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ *  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.
+ */
+
+#ifndef API_VIDEO_VIDEO_BROADCASTER_H_
+#define API_VIDEO_VIDEO_BROADCASTER_H_
+
+#include <optional>
+
+#include "api/scoped_refptr.h"
+#include "api/video/video_frame.h"
+#include "api/video/video_frame_buffer.h"
+#include "api/video/video_sink_interface.h"
+#include "api/video/video_source_interface.h"
+#include "api/video_track_source_constraints.h"
+#include "media/base/video_source_base.h"
+#include "rtc_base/synchronization/mutex.h"
+#include "rtc_base/thread_annotations.h"
+
+namespace webrtc {
+
+// VideoBroadcaster broadcast video frames to sinks and combines VideoSinkWants
+// from its sinks. It does that by implementing VideoSourceInterface and
+// VideoSinkInterface. The class is threadsafe; methods may be called on
+// any thread. This is needed because VideoStreamEncoder calls AddOrUpdateSink
+// both on the worker thread and on the encoder task queue.
+class VideoBroadcaster : public VideoSourceBase,
+                         public VideoSinkInterface<VideoFrame> {
+ public:
+  VideoBroadcaster();
+  ~VideoBroadcaster() override;
+
+  // Adds a new, or updates an already existing sink. If the sink is new and
+  // ProcessConstraints has been called previously, the new sink's
+  // OnConstraintsCalled method will be invoked with the most recent
+  // constraints.
+  void AddOrUpdateSink(VideoSinkInterface<VideoFrame>* sink,
+                       const VideoSinkWants& wants) override;
+  void RemoveSink(VideoSinkInterface<VideoFrame>* sink) override;
+
+  // Returns true if the next frame will be delivered to at least one sink.
+  bool frame_wanted() const;
+
+  // Returns VideoSinkWants a source is requested to fulfill. They are
+  // aggregated by all VideoSinkWants from all sinks.
+  VideoSinkWants wants() const;
+
+  // This method ensures that if a sink sets rotation_applied == true,
+  // it will never receive a frame with pending rotation. Our caller
+  // may pass in frames without precise synchronization with changes
+  // to the VideoSinkWants.
+  void OnFrame(const VideoFrame& frame) override;
+
+  void OnDiscardedFrame() override;
+
+  // Called on the network thread when constraints change. Forwards the
+  // constraints to sinks added with AddOrUpdateSink via OnConstraintsChanged.
+  void ProcessConstraints(const VideoTrackSourceConstraints& constraints);
+
+ protected:
+  void UpdateWants() RTC_EXCLUSIVE_LOCKS_REQUIRED(sinks_and_wants_lock_);
+  const scoped_refptr<VideoFrameBuffer>& GetBlackFrameBuffer(int width,
+                                                             int height)
+      RTC_EXCLUSIVE_LOCKS_REQUIRED(sinks_and_wants_lock_);
+
+  mutable Mutex sinks_and_wants_lock_;
+
+  VideoSinkWants current_wants_ RTC_GUARDED_BY(sinks_and_wants_lock_);
+  scoped_refptr<VideoFrameBuffer> black_frame_buffer_;
+  bool previous_frame_sent_to_all_sinks_ RTC_GUARDED_BY(sinks_and_wants_lock_) =
+      true;
+  std::optional<VideoTrackSourceConstraints> last_constraints_
+      RTC_GUARDED_BY(sinks_and_wants_lock_);
+};
+
+}  //  namespace webrtc
+
+#endif  // API_VIDEO_VIDEO_BROADCASTER_H_
diff --git a/media/base/video_broadcaster_unittest.cc b/api/video/video_broadcaster_unittest.cc
similarity index 99%
rename from media/base/video_broadcaster_unittest.cc
rename to api/video/video_broadcaster_unittest.cc
index 721c40b..c9c8953 100644
--- a/media/base/video_broadcaster_unittest.cc
+++ b/api/video/video_broadcaster_unittest.cc
@@ -8,7 +8,7 @@
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
-#include "media/base/video_broadcaster.h"
+#include "api/video/video_broadcaster.h"
 
 #include <limits>
 #include <optional>
diff --git a/media/base/video_common.cc b/api/video/video_common.cc
similarity index 98%
rename from media/base/video_common.cc
rename to api/video/video_common.cc
index da2221a..a32adc6 100644
--- a/media/base/video_common.cc
+++ b/api/video/video_common.cc
@@ -8,7 +8,7 @@
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
-#include "media/base/video_common.h"
+#include "api/video/video_common.h"
 
 #include <cstdint>
 #include <string>
diff --git a/api/video/video_common.h b/api/video/video_common.h
new file mode 100644
index 0000000..c4a4522
--- /dev/null
+++ b/api/video/video_common.h
@@ -0,0 +1,223 @@
+/*
+ *  Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
+ *
+ *  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.
+ */
+
+// Common definition for video, including fourcc and VideoFormat.
+
+#ifndef API_VIDEO_VIDEO_COMMON_H_
+#define API_VIDEO_VIDEO_COMMON_H_
+
+#include <stdint.h>
+
+#include <string>
+
+#include "rtc_base/system/rtc_export.h"
+#include "rtc_base/time_utils.h"
+
+namespace webrtc {
+
+//////////////////////////////////////////////////////////////////////////////
+// Definition of FourCC codes
+//////////////////////////////////////////////////////////////////////////////
+// Convert four characters to a FourCC code.
+// Needs to be a macro otherwise the OS X compiler complains when the kFormat*
+// constants are used in a switch.
+#define CRICKET_FOURCC_LOW(a, b) \
+  ((static_cast<uint32_t>(a)) | (static_cast<uint32_t>(b) << 8))
+#define CRICKET_FOURCC_HIGH(c, d) \
+  ((static_cast<uint32_t>(c) << 16) | (static_cast<uint32_t>(d) << 24))
+#define CRICKET_FOURCC(a, b, c, d) \
+  (CRICKET_FOURCC_LOW(a, b) | CRICKET_FOURCC_HIGH(c, d))
+// Some pages discussing FourCC codes:
+//   http://www.fourcc.org/yuv.php
+//   http://v4l2spec.bytesex.org/spec/book1.htm
+//   http://developer.apple.com/quicktime/icefloe/dispatch020.html
+//   http://msdn.microsoft.com/library/windows/desktop/dd206750.aspx#nv12
+//   http://people.xiph.org/~xiphmont/containers/nut/nut4cc.txt
+
+// FourCC codes grouped according to implementation efficiency.
+// Primary formats should convert in 1 efficient step.
+// Secondary formats are converted in 2 steps.
+// Auxiliary formats call primary converters.
+enum FourCC {
+  // 9 Primary YUV formats: 5 planar, 2 biplanar, 2 packed.
+  FOURCC_I420 = CRICKET_FOURCC('I', '4', '2', '0'),
+  FOURCC_I422 = CRICKET_FOURCC('I', '4', '2', '2'),
+  FOURCC_I444 = CRICKET_FOURCC('I', '4', '4', '4'),
+  FOURCC_I411 = CRICKET_FOURCC('I', '4', '1', '1'),
+  FOURCC_I400 = CRICKET_FOURCC('I', '4', '0', '0'),
+  FOURCC_NV21 = CRICKET_FOURCC('N', 'V', '2', '1'),
+  FOURCC_NV12 = CRICKET_FOURCC('N', 'V', '1', '2'),
+  FOURCC_YUY2 = CRICKET_FOURCC('Y', 'U', 'Y', '2'),
+  FOURCC_UYVY = CRICKET_FOURCC('U', 'Y', 'V', 'Y'),
+
+  // 2 Secondary YUV formats: row biplanar.
+  FOURCC_M420 = CRICKET_FOURCC('M', '4', '2', '0'),
+
+  // 9 Primary RGB formats: 4 32 bpp, 2 24 bpp, 3 16 bpp.
+  FOURCC_ARGB = CRICKET_FOURCC('A', 'R', 'G', 'B'),
+  FOURCC_BGRA = CRICKET_FOURCC('B', 'G', 'R', 'A'),
+  FOURCC_ABGR = CRICKET_FOURCC('A', 'B', 'G', 'R'),
+  FOURCC_24BG = CRICKET_FOURCC('2', '4', 'B', 'G'),
+  FOURCC_RAW = CRICKET_FOURCC('r', 'a', 'w', ' '),
+  FOURCC_RGBA = CRICKET_FOURCC('R', 'G', 'B', 'A'),
+  FOURCC_RGBP = CRICKET_FOURCC('R', 'G', 'B', 'P'),  // bgr565.
+  FOURCC_RGBO = CRICKET_FOURCC('R', 'G', 'B', 'O'),  // abgr1555.
+  FOURCC_R444 = CRICKET_FOURCC('R', '4', '4', '4'),  // argb4444.
+
+  // 4 Secondary RGB formats: 4 Bayer Patterns.
+  FOURCC_RGGB = CRICKET_FOURCC('R', 'G', 'G', 'B'),
+  FOURCC_BGGR = CRICKET_FOURCC('B', 'G', 'G', 'R'),
+  FOURCC_GRBG = CRICKET_FOURCC('G', 'R', 'B', 'G'),
+  FOURCC_GBRG = CRICKET_FOURCC('G', 'B', 'R', 'G'),
+
+  // 1 Primary Compressed YUV format.
+  FOURCC_MJPG = CRICKET_FOURCC('M', 'J', 'P', 'G'),
+
+  // 5 Auxiliary YUV variations: 3 with U and V planes are swapped, 1 Alias.
+  FOURCC_YV12 = CRICKET_FOURCC('Y', 'V', '1', '2'),
+  FOURCC_YV16 = CRICKET_FOURCC('Y', 'V', '1', '6'),
+  FOURCC_YV24 = CRICKET_FOURCC('Y', 'V', '2', '4'),
+  FOURCC_YU12 = CRICKET_FOURCC('Y', 'U', '1', '2'),  // Linux version of I420.
+  FOURCC_J420 = CRICKET_FOURCC('J', '4', '2', '0'),
+  FOURCC_J400 = CRICKET_FOURCC('J', '4', '0', '0'),
+
+  // 14 Auxiliary aliases.  CanonicalFourCC() maps these to canonical FOURCC.
+  FOURCC_IYUV = CRICKET_FOURCC('I', 'Y', 'U', 'V'),  // Alias for I420.
+  FOURCC_YU16 = CRICKET_FOURCC('Y', 'U', '1', '6'),  // Alias for I422.
+  FOURCC_YU24 = CRICKET_FOURCC('Y', 'U', '2', '4'),  // Alias for I444.
+  FOURCC_YUYV = CRICKET_FOURCC('Y', 'U', 'Y', 'V'),  // Alias for YUY2.
+  FOURCC_YUVS = CRICKET_FOURCC('y', 'u', 'v', 's'),  // Alias for YUY2 on Mac.
+  FOURCC_HDYC = CRICKET_FOURCC('H', 'D', 'Y', 'C'),  // Alias for UYVY.
+  FOURCC_2VUY = CRICKET_FOURCC('2', 'v', 'u', 'y'),  // Alias for UYVY on Mac.
+  FOURCC_JPEG = CRICKET_FOURCC('J', 'P', 'E', 'G'),  // Alias for MJPG.
+  FOURCC_DMB1 = CRICKET_FOURCC('d', 'm', 'b', '1'),  // Alias for MJPG on Mac.
+  FOURCC_BA81 = CRICKET_FOURCC('B', 'A', '8', '1'),  // Alias for BGGR.
+  FOURCC_RGB3 = CRICKET_FOURCC('R', 'G', 'B', '3'),  // Alias for RAW.
+  FOURCC_BGR3 = CRICKET_FOURCC('B', 'G', 'R', '3'),  // Alias for 24BG.
+  FOURCC_CM32 = CRICKET_FOURCC(0, 0, 0, 32),  // BGRA kCMPixelFormat_32ARGB
+  FOURCC_CM24 = CRICKET_FOURCC(0, 0, 0, 24),  // RAW kCMPixelFormat_24RGB
+
+  // 1 Auxiliary compressed YUV format set aside for capturer.
+  FOURCC_H264 = CRICKET_FOURCC('H', '2', '6', '4'),
+};
+
+#undef CRICKET_FOURCC_LOW
+#undef CRICKET_FOURCC_HIGH
+#undef CRICKET_FOURCC
+
+// Match any fourcc.
+
+// We move this out of the enum because using it in many places caused
+// the compiler to get grumpy, presumably since the above enum is
+// backed by an int.
+static const uint32_t FOURCC_ANY = 0xFFFFFFFF;
+
+// Converts fourcc aliases into canonical ones.
+uint32_t CanonicalFourCC(uint32_t fourcc);
+
+// Get FourCC code as a string.
+inline std::string GetFourccName(uint32_t fourcc) {
+  std::string name;
+  name.push_back(static_cast<char>(fourcc & 0xFF));
+  name.push_back(static_cast<char>((fourcc >> 8) & 0xFF));
+  name.push_back(static_cast<char>((fourcc >> 16) & 0xFF));
+  name.push_back(static_cast<char>((fourcc >> 24) & 0xFF));
+  return name;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+// Definition of VideoFormat.
+//////////////////////////////////////////////////////////////////////////////
+
+// VideoFormat with Plain Old Data for global variables.
+struct VideoFormatPod {
+  int width;         // Number of pixels.
+  int height;        // Number of pixels.
+  int64_t interval;  // Nanoseconds.
+  uint32_t fourcc;  // Color space. FOURCC_ANY means that any color space is OK.
+};
+
+struct RTC_EXPORT VideoFormat : VideoFormatPod {
+  static const int64_t kMinimumInterval =
+      kNumNanosecsPerSec / 10000;  // 10k fps.
+
+  VideoFormat() { Construct(0, 0, 0, 0); }
+
+  VideoFormat(int w, int h, int64_t interval_ns, uint32_t cc) {
+    Construct(w, h, interval_ns, cc);
+  }
+
+  explicit VideoFormat(const VideoFormatPod& format) {
+    Construct(format.width, format.height, format.interval, format.fourcc);
+  }
+
+  void Construct(int w, int h, int64_t interval_ns, uint32_t cc) {
+    width = w;
+    height = h;
+    interval = interval_ns;
+    fourcc = cc;
+  }
+
+  static int64_t FpsToInterval(int fps) {
+    return fps ? kNumNanosecsPerSec / fps : kMinimumInterval;
+  }
+
+  static int IntervalToFps(int64_t interval) {
+    if (!interval) {
+      return 0;
+    }
+    return static_cast<int>(kNumNanosecsPerSec / interval);
+  }
+
+  static float IntervalToFpsFloat(int64_t interval) {
+    if (!interval) {
+      return 0.f;
+    }
+    return static_cast<float>(kNumNanosecsPerSec) /
+           static_cast<float>(interval);
+  }
+
+  bool operator==(const VideoFormat& format) const {
+    return width == format.width && height == format.height &&
+           interval == format.interval && fourcc == format.fourcc;
+  }
+
+  bool operator!=(const VideoFormat& format) const {
+    return !(*this == format);
+  }
+
+  bool operator<(const VideoFormat& format) const {
+    return (fourcc < format.fourcc) ||
+           (fourcc == format.fourcc && width < format.width) ||
+           (fourcc == format.fourcc && width == format.width &&
+            height < format.height) ||
+           (fourcc == format.fourcc && width == format.width &&
+            height == format.height && interval > format.interval);
+  }
+
+  int framerate() const { return IntervalToFps(interval); }
+
+  // Check if both width and height are 0.
+  bool IsSize0x0() const { return 0 == width && 0 == height; }
+
+  // Check if this format is less than another one by comparing the resolution
+  // and frame rate.
+  bool IsPixelRateLess(const VideoFormat& format) const {
+    return width * height * framerate() <
+           format.width * format.height * format.framerate();
+  }
+
+  // Get a string presentation in the form of "fourcc width x height x fps"
+  std::string ToString() const;
+};
+
+}  //  namespace webrtc
+
+#endif  // API_VIDEO_VIDEO_COMMON_H_
diff --git a/media/base/video_common_unittest.cc b/api/video/video_common_unittest.cc
similarity index 98%
rename from media/base/video_common_unittest.cc
rename to api/video/video_common_unittest.cc
index 37b5c55..f2586a6 100644
--- a/media/base/video_common_unittest.cc
+++ b/api/video/video_common_unittest.cc
@@ -8,7 +8,7 @@
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
-#include "media/base/video_common.h"
+#include "api/video/video_common.h"
 
 #include "rtc_base/time_utils.h"
 #include "test/gtest.h"
diff --git a/examples/BUILD.gn b/examples/BUILD.gn
index 85edbfa..e1c281e 100644
--- a/examples/BUILD.gn
+++ b/examples/BUILD.gn
@@ -696,11 +696,11 @@
       "../api/task_queue",
       "../api/task_queue:pending_task_safety_flag",
       "../api/units:time_delta",
+      "../api/video:video_common",
       "../api/video:video_frame",
       "../api/video:video_rtp_headers",
       "../api/video_codecs:video_codecs_api",
       "../media:media_channel",
-      "../media:video_common",
       "../p2p:connection",
       "../p2p:port_allocator",
       "../pc:video_track_source",
diff --git a/examples/peerconnection/client/main_wnd.h b/examples/peerconnection/client/main_wnd.h
index 8f8ce7e..e21d7a5 100644
--- a/examples/peerconnection/client/main_wnd.h
+++ b/examples/peerconnection/client/main_wnd.h
@@ -16,10 +16,10 @@
 #include <string>
 
 #include "api/media_stream_interface.h"
+#include "api/video/video_common.h"
 #include "api/video/video_frame.h"
 #include "examples/peerconnection/client/peer_connection_client.h"
 #include "media/base/media_channel.h"
-#include "media/base/video_common.h"
 #if defined(WEBRTC_WIN)
 #include "rtc_base/win32.h"
 #endif  // WEBRTC_WIN
diff --git a/media/BUILD.gn b/media/BUILD.gn
index 1f1eac7..ed10a5e 100644
--- a/media/BUILD.gn
+++ b/media/BUILD.gn
@@ -57,7 +57,6 @@
     "base/video_common.h",  # Used downstream
   ]
   deps = [
-    ":adapted_video_track_source",
     ":codec",
     ":media_channel",
     ":media_channel_impl",
@@ -65,9 +64,6 @@
     ":rtc_media_config",
     ":rtp_utils",
     ":stream_params",
-    ":video_adapter",
-    ":video_broadcaster",
-    ":video_common",
     ":video_source_base",
     "../api:audio_options_api",
     "../api:call_api",
@@ -92,10 +88,14 @@
     "../api/transport:stun_types",
     "../api/transport/rtp:rtp_source",
     "../api/units:time_delta",
+    "../api/video:adapted_video_track_source",
     "../api/video:recordable_encoded_frame",
     "../api/video:resolution",
+    "../api/video:video_adapter",
     "../api/video:video_bitrate_allocation",
     "../api/video:video_bitrate_allocator_factory",
+    "../api/video:video_broadcaster",
+    "../api/video:video_common",
     "../api/video:video_frame",
     "../api/video:video_rtp_headers",
     "../api/video_codecs:scalability_mode",
@@ -129,52 +129,10 @@
   ]
 }
 
-rtc_library("adapted_video_track_source") {
-  sources = [
-    "base/adapted_video_track_source.cc",
-    "base/adapted_video_track_source.h",
-  ]
-  deps = [
-    ":video_adapter",
-    ":video_broadcaster",
-    "../api:media_stream_interface",
-    "../api:scoped_refptr",
-    "../api:video_track_source_constraints",
-    "../api/video:recordable_encoded_frame",
-    "../api/video:video_frame",
-    "../api/video:video_rtp_headers",
-    "../rtc_base:checks",
-    "../rtc_base:macromagic",
-    "../rtc_base:timeutils",
-    "../rtc_base/synchronization:mutex",
-    "../rtc_base/system:rtc_export",
-  ]
-}
-
 rtc_source_set("audio_source") {
   sources = [ "base/audio_source.h" ]
 }
 
-rtc_library("video_adapter") {
-  sources = [
-    "base/video_adapter.cc",
-    "base/video_adapter.h",
-  ]
-  deps = [
-    ":video_common",
-    "../api/video:resolution",
-    "../api/video:video_frame",
-    "../common_video",
-    "../rtc_base:checks",
-    "../rtc_base:logging",
-    "../rtc_base:macromagic",
-    "../rtc_base:stringutils",
-    "../rtc_base:timeutils",
-    "../rtc_base/synchronization:mutex",
-    "../rtc_base/system:rtc_export",
-  ]
-}
-
 rtc_library("video_source_base") {
   sources = [
     "base/video_source_base.cc",
@@ -190,39 +148,6 @@
   ]
 }
 
-rtc_library("video_broadcaster") {
-  sources = [
-    "base/video_broadcaster.cc",
-    "base/video_broadcaster.h",  # Used downstream
-  ]
-  deps = [
-    ":video_common",
-    ":video_source_base",
-    "../api:media_stream_interface",
-    "../api:scoped_refptr",
-    "../api:sequence_checker",
-    "../api:video_track_source_constraints",
-    "../api/video:video_frame",
-    "../api/video:video_rtp_headers",
-    "../rtc_base:checks",
-    "../rtc_base:logging",
-    "../rtc_base:macromagic",
-    "../rtc_base/synchronization:mutex",
-  ]
-}
-
-rtc_library("video_common") {
-  sources = [
-    "base/video_common.cc",
-    "base/video_common.h",
-  ]
-  deps = [
-    "../rtc_base:stringutils",
-    "../rtc_base:timeutils",
-    "../rtc_base/system:rtc_export",
-  ]
-}
-
 rtc_library("media_engine") {
   sources = [
     "base/media_engine.cc",
@@ -235,7 +160,6 @@
     ":rid_description",
     ":rtc_media_config",
     ":stream_params",
-    ":video_common",
     "../api:audio_options_api",
     "../api:field_trials_view",
     "../api:rtc_error",
@@ -251,6 +175,7 @@
     "../api/video:video_bitrate_allocation",
     "../api/video:video_bitrate_allocator_factory",
     "../api/video:video_codec_constants",
+    "../api/video:video_common",
     "../api/video_codecs:scalability_mode",
     "../api/video_codecs:scalability_mode_helper",
     "../api/video_codecs:video_codecs_api",
@@ -488,7 +413,6 @@
   ]
   deps = [
     ":rtc_sdp_video_format_utils",
-    ":video_common",
     "../api:fec_controller_api",
     "../api:field_trials_view",
     "../api:scoped_refptr",
@@ -500,6 +424,7 @@
     "../api/video:video_bitrate_allocation",
     "../api/video:video_bitrate_allocator",
     "../api/video:video_codec_constants",
+    "../api/video:video_common",
     "../api/video:video_frame",
     "../api/video:video_frame_type",
     "../api/video:video_rtp_headers",
@@ -826,7 +751,6 @@
       ":rtc_simulcast_encoder_adapter",
       ":rtp_utils",
       ":stream_params",
-      ":video_common",
       "../api:audio_options_api",
       "../api:call_api",
       "../api:fec_controller_api",
@@ -860,6 +784,7 @@
       "../api/video:resolution",
       "../api/video:video_bitrate_allocation",
       "../api/video:video_bitrate_allocator_factory",
+      "../api/video:video_common",
       "../api/video:video_frame",
       "../api/video:video_frame_type",
       "../api/video:video_rtp_headers",
@@ -971,7 +896,6 @@
         ":rtp_utils",
         ":stream_params",
         ":turn_utils",
-        ":video_common",
         "../api:audio_options_api",
         "../api:call_api",
         "../api:create_simulcast_test_fixture_api",
@@ -1022,6 +946,7 @@
         "../api/video:video_bitrate_allocator",
         "../api/video:video_bitrate_allocator_factory",
         "../api/video:video_codec_constants",
+        "../api/video:video_common",
         "../api/video:video_frame",
         "../api/video:video_frame_type",
         "../api/video:video_rtp_headers",
@@ -1104,9 +1029,6 @@
         "base/sdp_video_format_utils_unittest.cc",
         "base/stream_params_unittest.cc",
         "base/turn_utils_unittest.cc",
-        "base/video_adapter_unittest.cc",
-        "base/video_broadcaster_unittest.cc",
-        "base/video_common_unittest.cc",
         "engine/internal_decoder_factory_unittest.cc",
         "engine/internal_encoder_factory_unittest.cc",
         "engine/simulcast_encoder_adapter_unittest.cc",
diff --git a/media/base/adapted_video_track_source.h b/media/base/adapted_video_track_source.h
index b25439b..531dc66 100644
--- a/media/base/adapted_video_track_source.h
+++ b/media/base/adapted_video_track_source.h
@@ -11,98 +11,6 @@
 #ifndef MEDIA_BASE_ADAPTED_VIDEO_TRACK_SOURCE_H_
 #define MEDIA_BASE_ADAPTED_VIDEO_TRACK_SOURCE_H_
 
-#include <stdint.h>
-
-#include <optional>
-
-#include "api/media_stream_interface.h"
-#include "api/notifier.h"
-#include "api/video/recordable_encoded_frame.h"
-#include "api/video/video_frame.h"
-#include "api/video/video_sink_interface.h"
-#include "api/video/video_source_interface.h"
-#include "api/video_track_source_constraints.h"
-#include "media/base/video_adapter.h"
-#include "media/base/video_broadcaster.h"
-#include "rtc_base/synchronization/mutex.h"
-#include "rtc_base/system/rtc_export.h"
-#include "rtc_base/thread_annotations.h"
-
-namespace webrtc {
-
-// Base class for sources which needs video adaptation, e.g., video
-// capture sources. Sinks must be added and removed on one and only
-// one thread, while AdaptFrame and OnFrame may be called on any
-// thread.
-class RTC_EXPORT AdaptedVideoTrackSource
-    : public Notifier<VideoTrackSourceInterface> {
- public:
-  AdaptedVideoTrackSource();
-  ~AdaptedVideoTrackSource() override;
-
- protected:
-  // Allows derived classes to initialize `video_adapter_` with a custom
-  // alignment.
-  explicit AdaptedVideoTrackSource(int required_alignment);
-  // Checks the apply_rotation() flag. If the frame needs rotation, and it is a
-  // plain memory frame, it is rotated. Subclasses producing native frames must
-  // handle apply_rotation() themselves.
-  void OnFrame(const VideoFrame& frame);
-  // Indication from source that a frame was dropped.
-  void OnFrameDropped();
-
-  // Reports the appropriate frame size after adaptation. Returns true
-  // if a frame is wanted. Returns false if there are no interested
-  // sinks, or if the VideoAdapter decides to drop the frame.
-  bool AdaptFrame(int width,
-                  int height,
-                  int64_t time_us,
-                  int* out_width,
-                  int* out_height,
-                  int* crop_width,
-                  int* crop_height,
-                  int* crop_x,
-                  int* crop_y);
-
-  // Returns the current value of the apply_rotation flag, derived
-  // from the VideoSinkWants of registered sinks. The value is derived
-  // from sinks' wants, in AddOrUpdateSink and RemoveSink. Beware that
-  // when using this method from a different thread, the value may
-  // become stale before it is used.
-  bool apply_rotation();
-
-  VideoAdapter* video_adapter() { return &video_adapter_; }
-
- private:
-  // Implements VideoSourceInterface.
-  void AddOrUpdateSink(VideoSinkInterface<VideoFrame>* sink,
-                       const VideoSinkWants& wants) override;
-  void RemoveSink(VideoSinkInterface<VideoFrame>* sink) override;
-
-  // Part of VideoTrackSourceInterface.
-  bool GetStats(Stats* stats) override;
-
-  void OnSinkWantsChanged(const VideoSinkWants& wants);
-
-  // Encoded sinks not implemented for AdaptedVideoTrackSource.
-  bool SupportsEncodedOutput() const override { return false; }
-  void GenerateKeyFrame() override {}
-  void AddEncodedSink(
-      VideoSinkInterface<RecordableEncodedFrame>* /* sink */) override {}
-  void RemoveEncodedSink(
-      VideoSinkInterface<RecordableEncodedFrame>* /* sink */) override {}
-  void ProcessConstraints(
-      const VideoTrackSourceConstraints& constraints) override;
-
-  VideoAdapter video_adapter_;
-
-  Mutex stats_mutex_;
-  std::optional<Stats> stats_ RTC_GUARDED_BY(stats_mutex_);
-
-  VideoBroadcaster broadcaster_;
-};
-
-}  //  namespace webrtc
-
+#include "api/video/adapted_video_track_source.h"
 
 #endif  // MEDIA_BASE_ADAPTED_VIDEO_TRACK_SOURCE_H_
diff --git a/media/base/video_adapter.h b/media/base/video_adapter.h
index 5105124..1a5f4f0 100644
--- a/media/base/video_adapter.h
+++ b/media/base/video_adapter.h
@@ -11,163 +11,6 @@
 #ifndef MEDIA_BASE_VIDEO_ADAPTER_H_
 #define MEDIA_BASE_VIDEO_ADAPTER_H_
 
-#include <stdint.h>
-
-#include <optional>
-#include <string>
-#include <utility>
-
-#include "api/video/resolution.h"
-#include "api/video/video_source_interface.h"
-#include "common_video/framerate_controller.h"
-#include "media/base/video_common.h"
-#include "rtc_base/synchronization/mutex.h"
-#include "rtc_base/system/rtc_export.h"
-#include "rtc_base/thread_annotations.h"
-
-namespace webrtc {
-
-// VideoAdapter adapts an input video frame to an output frame based on the
-// specified input and output formats. The adaptation includes dropping frames
-// to reduce frame rate and scaling frames.
-// VideoAdapter is thread safe.
-class RTC_EXPORT VideoAdapter {
- public:
-  VideoAdapter();
-  // The source requests output frames whose width and height are divisible
-  // by `source_resolution_alignment`.
-  explicit VideoAdapter(int source_resolution_alignment);
-  virtual ~VideoAdapter();
-
-  VideoAdapter(const VideoAdapter&) = delete;
-  VideoAdapter& operator=(const VideoAdapter&) = delete;
-
-  // Return the adapted resolution and cropping parameters given the
-  // input resolution. The input frame should first be cropped, then
-  // scaled to the final output resolution. Returns true if the frame
-  // should be adapted, and false if it should be dropped.
-  bool AdaptFrameResolution(int in_width,
-                            int in_height,
-                            int64_t in_timestamp_ns,
-                            int* cropped_width,
-                            int* cropped_height,
-                            int* out_width,
-                            int* out_height) RTC_LOCKS_EXCLUDED(mutex_);
-
-  // DEPRECATED. Please use OnOutputFormatRequest below.
-  // TODO(asapersson): Remove this once it is no longer used.
-  // Requests the output frame size and frame interval from
-  // `AdaptFrameResolution` to not be larger than `format`. Also, the input
-  // frame size will be cropped to match the requested aspect ratio. The
-  // requested aspect ratio is orientation agnostic and will be adjusted to
-  // maintain the input orientation, so it doesn't matter if e.g. 1280x720 or
-  // 720x1280 is requested.
-  // Note: Should be called from the source only.
-  void OnOutputFormatRequest(const std::optional<VideoFormat>& format)
-      RTC_LOCKS_EXCLUDED(mutex_);
-
-  // Requests output frame size and frame interval from `AdaptFrameResolution`.
-  // `target_aspect_ratio`: The input frame size will be cropped to match the
-  // requested aspect ratio. The aspect ratio is orientation agnostic and will
-  // be adjusted to maintain the input orientation (i.e. it doesn't matter if
-  // e.g. <1280,720> or <720,1280> is requested).
-  // `max_pixel_count`: The maximum output frame size.
-  // `max_fps`: The maximum output framerate.
-  // Note: Should be called from the source only.
-  void OnOutputFormatRequest(
-      const std::optional<std::pair<int, int>>& target_aspect_ratio,
-      const std::optional<int>& max_pixel_count,
-      const std::optional<int>& max_fps) RTC_LOCKS_EXCLUDED(mutex_);
-
-  // Same as above, but allows setting two different target aspect ratios
-  // depending on incoming frame orientation. This gives more fine-grained
-  // control and can e.g. be used to force landscape video to be cropped to
-  // portrait video.
-  void OnOutputFormatRequest(
-      const std::optional<std::pair<int, int>>& target_landscape_aspect_ratio,
-      const std::optional<int>& max_landscape_pixel_count,
-      const std::optional<std::pair<int, int>>& target_portrait_aspect_ratio,
-      const std::optional<int>& max_portrait_pixel_count,
-      const std::optional<int>& max_fps) RTC_LOCKS_EXCLUDED(mutex_);
-
-  // Requests the output frame size from `AdaptFrameResolution` to have as close
-  // as possible to `sink_wants.target_pixel_count` pixels (if set)
-  // but no more than `sink_wants.max_pixel_count`.
-  // `sink_wants.max_framerate_fps` is essentially analogous to
-  // `sink_wants.max_pixel_count`, but for framerate rather than resolution.
-  // Set `sink_wants.max_pixel_count` and/or `sink_wants.max_framerate_fps` to
-  // std::numeric_limit<int>::max() if no upper limit is desired.
-  // The sink resolution alignment requirement is given by
-  // `sink_wants.resolution_alignment`.
-  // Note: Should be called from the sink only.
-  void OnSinkWants(const VideoSinkWants& sink_wants) RTC_LOCKS_EXCLUDED(mutex_);
-
-  // Returns maximum image area, which shouldn't impose any adaptations.
-  // Can return `numeric_limits<int>::max()` if no limit is set.
-  int GetTargetPixels() const;
-
-  // Returns current frame-rate limit.
-  // Can return `numeric_limits<float>::infinity()` if no limit is set.
-  float GetMaxFramerate() const;
-
- private:
-  // Determine if frame should be dropped based on input fps and requested fps.
-  bool DropFrame(int64_t in_timestamp_ns) RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
-
-  int frames_in_ RTC_GUARDED_BY(mutex_);      // Number of input frames.
-  int frames_out_ RTC_GUARDED_BY(mutex_);     // Number of output frames.
-  int frames_scaled_ RTC_GUARDED_BY(mutex_);  // Number of frames scaled.
-  int adaption_changes_
-      RTC_GUARDED_BY(mutex_);  // Number of changes in scale factor.
-  int previous_width_ RTC_GUARDED_BY(mutex_);  // Previous adapter output width.
-  int previous_height_
-      RTC_GUARDED_BY(mutex_);  // Previous adapter output height.
-
-  // The fixed source resolution alignment requirement.
-  const int source_resolution_alignment_;
-  // The currently applied resolution alignment, as given by the requirements:
-  //  - the fixed `source_resolution_alignment_`; and
-  //  - the latest `sink_wants.resolution_alignment`.
-  int resolution_alignment_ RTC_GUARDED_BY(mutex_);
-
-  // Max number of pixels/fps requested via calls to OnOutputFormatRequest,
-  // OnResolutionFramerateRequest respectively.
-  // The adapted output format is the minimum of these.
-  struct OutputFormatRequest {
-    std::optional<std::pair<int, int>> target_landscape_aspect_ratio;
-    std::optional<int> max_landscape_pixel_count;
-    std::optional<std::pair<int, int>> target_portrait_aspect_ratio;
-    std::optional<int> max_portrait_pixel_count;
-    std::optional<int> max_fps;
-
-    // For logging.
-    std::string ToString() const;
-  };
-
-  OutputFormatRequest output_format_request_ RTC_GUARDED_BY(mutex_);
-  int resolution_request_target_pixel_count_ RTC_GUARDED_BY(mutex_);
-  int resolution_request_max_pixel_count_ RTC_GUARDED_BY(mutex_);
-  int max_framerate_request_ RTC_GUARDED_BY(mutex_);
-  std::optional<Resolution> scale_resolution_down_to_ RTC_GUARDED_BY(mutex_);
-
-  // Stashed OutputFormatRequest that is used to save value of
-  // OnOutputFormatRequest in case all active encoders are using
-  // scale_resolution_down_to. I.e when all active encoders are using
-  // scale_resolution_down_to, the call to OnOutputFormatRequest is ignored
-  // and the value from scale_resolution_down_to is used instead (to scale/crop
-  // frame). This allows for an application to only use
-  // RtpEncodingParameters::request_resolution and get the same behavior as if
-  // it had used VideoAdapter::OnOutputFormatRequest.
-  std::optional<OutputFormatRequest> stashed_output_format_request_
-      RTC_GUARDED_BY(mutex_);
-
-  FramerateController framerate_controller_ RTC_GUARDED_BY(mutex_);
-
-  // The critical section to protect the above variables.
-  mutable Mutex mutex_;
-};
-
-}  //  namespace webrtc
-
+#include "api/video/video_adapter.h"
 
 #endif  // MEDIA_BASE_VIDEO_ADAPTER_H_
diff --git a/media/base/video_broadcaster.h b/media/base/video_broadcaster.h
index 7b77453..43be476 100644
--- a/media/base/video_broadcaster.h
+++ b/media/base/video_broadcaster.h
@@ -11,75 +11,6 @@
 #ifndef MEDIA_BASE_VIDEO_BROADCASTER_H_
 #define MEDIA_BASE_VIDEO_BROADCASTER_H_
 
-#include <optional>
-
-#include "api/scoped_refptr.h"
-#include "api/video/video_frame.h"
-#include "api/video/video_frame_buffer.h"
-#include "api/video/video_sink_interface.h"
-#include "api/video/video_source_interface.h"
-#include "api/video_track_source_constraints.h"
-#include "media/base/video_source_base.h"
-#include "rtc_base/synchronization/mutex.h"
-#include "rtc_base/thread_annotations.h"
-
-namespace webrtc {
-
-// VideoBroadcaster broadcast video frames to sinks and combines VideoSinkWants
-// from its sinks. It does that by implementing VideoSourceInterface and
-// VideoSinkInterface. The class is threadsafe; methods may be called on
-// any thread. This is needed because VideoStreamEncoder calls AddOrUpdateSink
-// both on the worker thread and on the encoder task queue.
-class VideoBroadcaster : public VideoSourceBase,
-                         public VideoSinkInterface<VideoFrame> {
- public:
-  VideoBroadcaster();
-  ~VideoBroadcaster() override;
-
-  // Adds a new, or updates an already existing sink. If the sink is new and
-  // ProcessConstraints has been called previously, the new sink's
-  // OnConstraintsCalled method will be invoked with the most recent
-  // constraints.
-  void AddOrUpdateSink(VideoSinkInterface<VideoFrame>* sink,
-                       const VideoSinkWants& wants) override;
-  void RemoveSink(VideoSinkInterface<VideoFrame>* sink) override;
-
-  // Returns true if the next frame will be delivered to at least one sink.
-  bool frame_wanted() const;
-
-  // Returns VideoSinkWants a source is requested to fulfill. They are
-  // aggregated by all VideoSinkWants from all sinks.
-  VideoSinkWants wants() const;
-
-  // This method ensures that if a sink sets rotation_applied == true,
-  // it will never receive a frame with pending rotation. Our caller
-  // may pass in frames without precise synchronization with changes
-  // to the VideoSinkWants.
-  void OnFrame(const VideoFrame& frame) override;
-
-  void OnDiscardedFrame() override;
-
-  // Called on the network thread when constraints change. Forwards the
-  // constraints to sinks added with AddOrUpdateSink via OnConstraintsChanged.
-  void ProcessConstraints(const VideoTrackSourceConstraints& constraints);
-
- protected:
-  void UpdateWants() RTC_EXCLUSIVE_LOCKS_REQUIRED(sinks_and_wants_lock_);
-  const scoped_refptr<VideoFrameBuffer>& GetBlackFrameBuffer(int width,
-                                                             int height)
-      RTC_EXCLUSIVE_LOCKS_REQUIRED(sinks_and_wants_lock_);
-
-  mutable Mutex sinks_and_wants_lock_;
-
-  VideoSinkWants current_wants_ RTC_GUARDED_BY(sinks_and_wants_lock_);
-  scoped_refptr<VideoFrameBuffer> black_frame_buffer_;
-  bool previous_frame_sent_to_all_sinks_ RTC_GUARDED_BY(sinks_and_wants_lock_) =
-      true;
-  std::optional<VideoTrackSourceConstraints> last_constraints_
-      RTC_GUARDED_BY(sinks_and_wants_lock_);
-};
-
-}  //  namespace webrtc
-
+#include "api/video/video_broadcaster.h"
 
 #endif  // MEDIA_BASE_VIDEO_BROADCASTER_H_
diff --git a/media/base/video_common.h b/media/base/video_common.h
index 010a78a..7ca3d4b 100644
--- a/media/base/video_common.h
+++ b/media/base/video_common.h
@@ -8,212 +8,9 @@
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
-// Common definition for video, including fourcc and VideoFormat.
-
 #ifndef MEDIA_BASE_VIDEO_COMMON_H_
 #define MEDIA_BASE_VIDEO_COMMON_H_
 
-#include <stdint.h>
+#include "api/video/video_common.h"
 
-#include <string>
-
-#include "rtc_base/system/rtc_export.h"
-#include "rtc_base/time_utils.h"
-
-namespace webrtc {
-
-//////////////////////////////////////////////////////////////////////////////
-// Definition of FourCC codes
-//////////////////////////////////////////////////////////////////////////////
-// Convert four characters to a FourCC code.
-// Needs to be a macro otherwise the OS X compiler complains when the kFormat*
-// constants are used in a switch.
-#define CRICKET_FOURCC(a, b, c, d)                                \
-  ((static_cast<uint32_t>(a)) | (static_cast<uint32_t>(b) << 8) | \
-   (static_cast<uint32_t>(c) << 16) | (static_cast<uint32_t>(d) << 24))
-// Some pages discussing FourCC codes:
-//   http://www.fourcc.org/yuv.php
-//   http://v4l2spec.bytesex.org/spec/book1.htm
-//   http://developer.apple.com/quicktime/icefloe/dispatch020.html
-//   http://msdn.microsoft.com/library/windows/desktop/dd206750.aspx#nv12
-//   http://people.xiph.org/~xiphmont/containers/nut/nut4cc.txt
-
-// FourCC codes grouped according to implementation efficiency.
-// Primary formats should convert in 1 efficient step.
-// Secondary formats are converted in 2 steps.
-// Auxilliary formats call primary converters.
-enum FourCC {
-  // 9 Primary YUV formats: 5 planar, 2 biplanar, 2 packed.
-  FOURCC_I420 = CRICKET_FOURCC('I', '4', '2', '0'),
-  FOURCC_I422 = CRICKET_FOURCC('I', '4', '2', '2'),
-  FOURCC_I444 = CRICKET_FOURCC('I', '4', '4', '4'),
-  FOURCC_I411 = CRICKET_FOURCC('I', '4', '1', '1'),
-  FOURCC_I400 = CRICKET_FOURCC('I', '4', '0', '0'),
-  FOURCC_NV21 = CRICKET_FOURCC('N', 'V', '2', '1'),
-  FOURCC_NV12 = CRICKET_FOURCC('N', 'V', '1', '2'),
-  FOURCC_YUY2 = CRICKET_FOURCC('Y', 'U', 'Y', '2'),
-  FOURCC_UYVY = CRICKET_FOURCC('U', 'Y', 'V', 'Y'),
-
-  // 2 Secondary YUV formats: row biplanar.
-  FOURCC_M420 = CRICKET_FOURCC('M', '4', '2', '0'),
-
-  // 9 Primary RGB formats: 4 32 bpp, 2 24 bpp, 3 16 bpp.
-  FOURCC_ARGB = CRICKET_FOURCC('A', 'R', 'G', 'B'),
-  FOURCC_BGRA = CRICKET_FOURCC('B', 'G', 'R', 'A'),
-  FOURCC_ABGR = CRICKET_FOURCC('A', 'B', 'G', 'R'),
-  FOURCC_24BG = CRICKET_FOURCC('2', '4', 'B', 'G'),
-  FOURCC_RAW = CRICKET_FOURCC('r', 'a', 'w', ' '),
-  FOURCC_RGBA = CRICKET_FOURCC('R', 'G', 'B', 'A'),
-  FOURCC_RGBP = CRICKET_FOURCC('R', 'G', 'B', 'P'),  // bgr565.
-  FOURCC_RGBO = CRICKET_FOURCC('R', 'G', 'B', 'O'),  // abgr1555.
-  FOURCC_R444 = CRICKET_FOURCC('R', '4', '4', '4'),  // argb4444.
-
-  // 4 Secondary RGB formats: 4 Bayer Patterns.
-  FOURCC_RGGB = CRICKET_FOURCC('R', 'G', 'G', 'B'),
-  FOURCC_BGGR = CRICKET_FOURCC('B', 'G', 'G', 'R'),
-  FOURCC_GRBG = CRICKET_FOURCC('G', 'R', 'B', 'G'),
-  FOURCC_GBRG = CRICKET_FOURCC('G', 'B', 'R', 'G'),
-
-  // 1 Primary Compressed YUV format.
-  FOURCC_MJPG = CRICKET_FOURCC('M', 'J', 'P', 'G'),
-
-  // 5 Auxiliary YUV variations: 3 with U and V planes are swapped, 1 Alias.
-  FOURCC_YV12 = CRICKET_FOURCC('Y', 'V', '1', '2'),
-  FOURCC_YV16 = CRICKET_FOURCC('Y', 'V', '1', '6'),
-  FOURCC_YV24 = CRICKET_FOURCC('Y', 'V', '2', '4'),
-  FOURCC_YU12 = CRICKET_FOURCC('Y', 'U', '1', '2'),  // Linux version of I420.
-  FOURCC_J420 = CRICKET_FOURCC('J', '4', '2', '0'),
-  FOURCC_J400 = CRICKET_FOURCC('J', '4', '0', '0'),
-
-  // 14 Auxiliary aliases.  CanonicalFourCC() maps these to canonical FOURCC.
-  FOURCC_IYUV = CRICKET_FOURCC('I', 'Y', 'U', 'V'),  // Alias for I420.
-  FOURCC_YU16 = CRICKET_FOURCC('Y', 'U', '1', '6'),  // Alias for I422.
-  FOURCC_YU24 = CRICKET_FOURCC('Y', 'U', '2', '4'),  // Alias for I444.
-  FOURCC_YUYV = CRICKET_FOURCC('Y', 'U', 'Y', 'V'),  // Alias for YUY2.
-  FOURCC_YUVS = CRICKET_FOURCC('y', 'u', 'v', 's'),  // Alias for YUY2 on Mac.
-  FOURCC_HDYC = CRICKET_FOURCC('H', 'D', 'Y', 'C'),  // Alias for UYVY.
-  FOURCC_2VUY = CRICKET_FOURCC('2', 'v', 'u', 'y'),  // Alias for UYVY on Mac.
-  FOURCC_JPEG = CRICKET_FOURCC('J', 'P', 'E', 'G'),  // Alias for MJPG.
-  FOURCC_DMB1 = CRICKET_FOURCC('d', 'm', 'b', '1'),  // Alias for MJPG on Mac.
-  FOURCC_BA81 = CRICKET_FOURCC('B', 'A', '8', '1'),  // Alias for BGGR.
-  FOURCC_RGB3 = CRICKET_FOURCC('R', 'G', 'B', '3'),  // Alias for RAW.
-  FOURCC_BGR3 = CRICKET_FOURCC('B', 'G', 'R', '3'),  // Alias for 24BG.
-  FOURCC_CM32 = CRICKET_FOURCC(0, 0, 0, 32),  // BGRA kCMPixelFormat_32ARGB
-  FOURCC_CM24 = CRICKET_FOURCC(0, 0, 0, 24),  // RAW kCMPixelFormat_24RGB
-
-  // 1 Auxiliary compressed YUV format set aside for capturer.
-  FOURCC_H264 = CRICKET_FOURCC('H', '2', '6', '4'),
-};
-
-#undef CRICKET_FOURCC
-
-// Match any fourcc.
-
-// We move this out of the enum because using it in many places caused
-// the compiler to get grumpy, presumably since the above enum is
-// backed by an int.
-static const uint32_t FOURCC_ANY = 0xFFFFFFFF;
-
-// Converts fourcc aliases into canonical ones.
-uint32_t CanonicalFourCC(uint32_t fourcc);
-
-// Get FourCC code as a string.
-inline std::string GetFourccName(uint32_t fourcc) {
-  std::string name;
-  name.push_back(static_cast<char>(fourcc & 0xFF));
-  name.push_back(static_cast<char>((fourcc >> 8) & 0xFF));
-  name.push_back(static_cast<char>((fourcc >> 16) & 0xFF));
-  name.push_back(static_cast<char>((fourcc >> 24) & 0xFF));
-  return name;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-// Definition of VideoFormat.
-//////////////////////////////////////////////////////////////////////////////
-
-// VideoFormat with Plain Old Data for global variables.
-struct VideoFormatPod {
-  int width;         // Number of pixels.
-  int height;        // Number of pixels.
-  int64_t interval;  // Nanoseconds.
-  uint32_t fourcc;  // Color space. FOURCC_ANY means that any color space is OK.
-};
-
-struct RTC_EXPORT VideoFormat : VideoFormatPod {
-  static const int64_t kMinimumInterval =
-      kNumNanosecsPerSec / 10000;  // 10k fps.
-
-  VideoFormat() { Construct(0, 0, 0, 0); }
-
-  VideoFormat(int w, int h, int64_t interval_ns, uint32_t cc) {
-    Construct(w, h, interval_ns, cc);
-  }
-
-  explicit VideoFormat(const VideoFormatPod& format) {
-    Construct(format.width, format.height, format.interval, format.fourcc);
-  }
-
-  void Construct(int w, int h, int64_t interval_ns, uint32_t cc) {
-    width = w;
-    height = h;
-    interval = interval_ns;
-    fourcc = cc;
-  }
-
-  static int64_t FpsToInterval(int fps) {
-    return fps ? kNumNanosecsPerSec / fps : kMinimumInterval;
-  }
-
-  static int IntervalToFps(int64_t interval) {
-    if (!interval) {
-      return 0;
-    }
-    return static_cast<int>(kNumNanosecsPerSec / interval);
-  }
-
-  static float IntervalToFpsFloat(int64_t interval) {
-    if (!interval) {
-      return 0.f;
-    }
-    return static_cast<float>(kNumNanosecsPerSec) /
-           static_cast<float>(interval);
-  }
-
-  bool operator==(const VideoFormat& format) const {
-    return width == format.width && height == format.height &&
-           interval == format.interval && fourcc == format.fourcc;
-  }
-
-  bool operator!=(const VideoFormat& format) const {
-    return !(*this == format);
-  }
-
-  bool operator<(const VideoFormat& format) const {
-    return (fourcc < format.fourcc) ||
-           (fourcc == format.fourcc && width < format.width) ||
-           (fourcc == format.fourcc && width == format.width &&
-            height < format.height) ||
-           (fourcc == format.fourcc && width == format.width &&
-            height == format.height && interval > format.interval);
-  }
-
-  int framerate() const { return IntervalToFps(interval); }
-
-  // Check if both width and height are 0.
-  bool IsSize0x0() const { return 0 == width && 0 == height; }
-
-  // Check if this format is less than another one by comparing the resolution
-  // and frame rate.
-  bool IsPixelRateLess(const VideoFormat& format) const {
-    return width * height * framerate() <
-           format.width * format.height * format.framerate();
-  }
-
-  // Get a string presentation in the form of "fourcc width x height x fps"
-  std::string ToString() const;
-};
-
-}  //  namespace webrtc
-
-
-#endif  // MEDIA_BASE_VIDEO_COMMON_H_
+#endif  // MEDIA_BASE_VIDEO_COMMON_H_
\ No newline at end of file
diff --git a/media/engine/webrtc_video_engine_unittest.cc b/media/engine/webrtc_video_engine_unittest.cc
index aeb78b5..41d9e30 100644
--- a/media/engine/webrtc_video_engine_unittest.cc
+++ b/media/engine/webrtc_video_engine_unittest.cc
@@ -59,6 +59,7 @@
 #include "api/video/video_bitrate_allocator_factory.h"
 #include "api/video/video_codec_constants.h"
 #include "api/video/video_codec_type.h"
+#include "api/video/video_common.h"
 #include "api/video/video_content_type.h"
 #include "api/video/video_frame_buffer.h"
 #include "api/video/video_rotation.h"
@@ -98,7 +99,6 @@
 #include "media/base/rid_description.h"
 #include "media/base/stream_params.h"
 #include "media/base/test_utils.h"
-#include "media/base/video_common.h"
 #include "media/engine/fake_webrtc_call.h"
 #include "media/engine/fake_webrtc_video_engine.h"
 #include "modules/rtp_rtcp/include/report_block_data.h"
diff --git a/modules/desktop_capture/BUILD.gn b/modules/desktop_capture/BUILD.gn
index a845b09..d736529 100644
--- a/modules/desktop_capture/BUILD.gn
+++ b/modules/desktop_capture/BUILD.gn
@@ -38,7 +38,7 @@
 
   deps = [
     "../../api:scoped_refptr",
-    "../../media:video_common",
+    "../../api/video:video_common",
     "../../rtc_base:checks",
     "../../rtc_base:refcount",
     "../../rtc_base:stringutils",
@@ -289,7 +289,7 @@
     "../../api/environment",
     "../../api/units:time_delta",
     "../../api/units:timestamp",
-    "../../media:video_common",
+    "../../api/video:video_common",
     "../../rtc_base/containers:flat_map",
     "../../rtc_base/containers:flat_set",
     "../../system_wrappers",
diff --git a/modules/desktop_capture/desktop_frame.h b/modules/desktop_capture/desktop_frame.h
index bda6b7f..006e11c 100644
--- a/modules/desktop_capture/desktop_frame.h
+++ b/modules/desktop_capture/desktop_frame.h
@@ -18,7 +18,7 @@
 #include <vector>
 
 #include "absl/base/nullability.h"
-#include "media/base/video_common.h"
+#include "api/video/video_common.h"
 #include "modules/desktop_capture/desktop_geometry.h"
 #include "modules/desktop_capture/desktop_region.h"
 #include "modules/desktop_capture/frame_texture.h"
diff --git a/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc b/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc
index 7366fd5..a57c386 100644
--- a/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc
+++ b/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc
@@ -40,7 +40,7 @@
 #include <vector>
 
 #include "api/scoped_refptr.h"
-#include "media/base/video_common.h"
+#include "api/video/video_common.h"
 #include "modules/desktop_capture/desktop_capture_types.h"
 #include "modules/desktop_capture/desktop_capturer.h"
 #include "modules/desktop_capture/desktop_frame.h"
diff --git a/modules/desktop_capture/linux/x11/screen_capturer_x11.cc b/modules/desktop_capture/linux/x11/screen_capturer_x11.cc
index fb11c91..6088a32 100644
--- a/modules/desktop_capture/linux/x11/screen_capturer_x11.cc
+++ b/modules/desktop_capture/linux/x11/screen_capturer_x11.cc
@@ -27,7 +27,7 @@
 
 #include "api/units/time_delta.h"
 #include "api/units/timestamp.h"
-#include "media/base/video_common.h"
+#include "api/video/video_common.h"
 #include "modules/desktop_capture/desktop_capture_options.h"
 #include "modules/desktop_capture/desktop_capture_types.h"
 #include "modules/desktop_capture/desktop_capturer.h"
diff --git a/modules/desktop_capture/linux/x11/window_capturer_x11.cc b/modules/desktop_capture/linux/x11/window_capturer_x11.cc
index 1cd97d2..c31aa80 100644
--- a/modules/desktop_capture/linux/x11/window_capturer_x11.cc
+++ b/modules/desktop_capture/linux/x11/window_capturer_x11.cc
@@ -29,7 +29,7 @@
 #include "api/scoped_refptr.h"
 #include "api/units/time_delta.h"
 #include "api/units/timestamp.h"
-#include "media/base/video_common.h"
+#include "api/video/video_common.h"
 #include "modules/desktop_capture/desktop_capture_options.h"
 #include "modules/desktop_capture/desktop_capture_types.h"
 #include "modules/desktop_capture/desktop_capturer.h"
diff --git a/modules/video_capture/BUILD.gn b/modules/video_capture/BUILD.gn
index 5a6fab0..0fffdf2 100644
--- a/modules/video_capture/BUILD.gn
+++ b/modules/video_capture/BUILD.gn
@@ -59,9 +59,9 @@
       "../../api:make_ref_counted",
       "../../api:scoped_refptr",
       "../../api:sequence_checker",
+      "../../api/video:video_common",
       "../../api/video:video_rtp_headers",
       "../../common_video",
-      "../../media:video_common",
       "../../rtc_base:checks",
       "../../rtc_base:logging",
       "../../rtc_base:macromagic",
diff --git a/modules/video_capture/linux/video_capture_v4l2.cc b/modules/video_capture/linux/video_capture_v4l2.cc
index 0eef1ff..d5f8209 100644
--- a/modules/video_capture/linux/video_capture_v4l2.cc
+++ b/modules/video_capture/linux/video_capture_v4l2.cc
@@ -24,8 +24,8 @@
 #include <new>
 
 #include "api/sequence_checker.h"
+#include "api/video/video_common.h"
 #include "common_video/libyuv/include/webrtc_libyuv.h"
-#include "media/base/video_common.h"
 #include "modules/video_capture/video_capture_defines.h"
 #include "modules/video_capture/video_capture_impl.h"
 #include "rtc_base/checks.h"
diff --git a/pc/BUILD.gn b/pc/BUILD.gn
index 17e4fc5..8c8c2af 100644
--- a/pc/BUILD.gn
+++ b/pc/BUILD.gn
@@ -1955,6 +1955,7 @@
     ":video_track_source",
     "../api:sequence_checker",
     "../api/video:recordable_encoded_frame",
+    "../api/video:video_broadcaster",
     "../api/video:video_frame",
     "../media:rtc_media_base",
     "../rtc_base:checks",
@@ -4464,6 +4465,7 @@
       "../api/units:time_delta",
       "../api/units:timestamp",
       "../api/video:resolution",
+      "../api/video:video_broadcaster",
       "../api/video:video_frame",
       "../api/video:video_rtp_headers",
       "../api/video_codecs:video_codecs_api",
diff --git a/pc/test/fake_periodic_video_source.h b/pc/test/fake_periodic_video_source.h
index 6f99b95..c218055 100644
--- a/pc/test/fake_periodic_video_source.h
+++ b/pc/test/fake_periodic_video_source.h
@@ -16,12 +16,12 @@
 #include "api/sequence_checker.h"
 #include "api/units/time_delta.h"
 #include "api/units/timestamp.h"
+#include "api/video/video_broadcaster.h"
 #include "api/video/video_frame.h"
 #include "api/video/video_rotation.h"
 #include "api/video/video_sink_interface.h"
 #include "api/video/video_source_interface.h"
 #include "media/base/fake_frame_source.h"
-#include "media/base/video_broadcaster.h"
 #include "rtc_base/checks.h"
 #include "rtc_base/synchronization/mutex.h"
 #include "rtc_base/task_queue_for_test.h"
diff --git a/pc/test/fake_video_track_source.h b/pc/test/fake_video_track_source.h
index 241f73a..947c767 100644
--- a/pc/test/fake_video_track_source.h
+++ b/pc/test/fake_video_track_source.h
@@ -14,9 +14,9 @@
 #include "api/make_ref_counted.h"
 #include "api/media_stream_interface.h"
 #include "api/scoped_refptr.h"
+#include "api/video/video_broadcaster.h"
 #include "api/video/video_frame.h"
 #include "api/video/video_source_interface.h"
-#include "media/base/video_broadcaster.h"
 #include "pc/video_track_source.h"
 
 namespace webrtc {
diff --git a/pc/video_rtp_track_source.h b/pc/video_rtp_track_source.h
index 96051016..3c33e20 100644
--- a/pc/video_rtp_track_source.h
+++ b/pc/video_rtp_track_source.h
@@ -15,10 +15,10 @@
 
 #include "api/sequence_checker.h"
 #include "api/video/recordable_encoded_frame.h"
+#include "api/video/video_broadcaster.h"
 #include "api/video/video_frame.h"
 #include "api/video/video_sink_interface.h"
 #include "api/video/video_source_interface.h"
-#include "media/base/video_broadcaster.h"
 #include "pc/video_track_source.h"
 #include "rtc_base/synchronization/mutex.h"
 #include "rtc_base/system/no_unique_address.h"
diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn
index c82d3d6..b7f8a41 100644
--- a/sdk/BUILD.gn
+++ b/sdk/BUILD.gn
@@ -1754,11 +1754,11 @@
         ":wrapped_native_codec_objc",
         "../api:make_ref_counted",
         "../api/environment",
+        "../api/video:adapted_video_track_source",
         "../api/video:video_frame",
         "../api/video:video_rtp_headers",
         "../api/video_codecs:video_codecs_api",
         "../common_video",
-        "../media:adapted_video_track_source",
         "../media:codec",
         "../media:rtc_audio_video",
         "../media:rtc_media_base",
diff --git a/sdk/android/BUILD.gn b/sdk/android/BUILD.gn
index 9d222c8..e947ec0 100644
--- a/sdk/android/BUILD.gn
+++ b/sdk/android/BUILD.gn
@@ -738,6 +738,7 @@
       "../../api/task_queue",
       "../../api/task_queue:pending_task_safety_flag",
       "../../api/units:data_rate",
+      "../../api/video:adapted_video_track_source",
       "../../api/video:encoded_image",
       "../../api/video:render_resolution",
       "../../api/video:video_bitrate_allocation",
diff --git a/sdk/android/src/jni/android_video_track_source.cc b/sdk/android/src/jni/android_video_track_source.cc
index 7ac66c7..9e4f188 100644
--- a/sdk/android/src/jni/android_video_track_source.cc
+++ b/sdk/android/src/jni/android_video_track_source.cc
@@ -20,10 +20,10 @@
 #include "api/media_stream_interface.h"
 #include "api/scoped_refptr.h"
 #include "api/task_queue/pending_task_safety_flag.h"
+#include "api/video/adapted_video_track_source.h"
 #include "api/video/video_frame.h"
 #include "api/video/video_frame_buffer.h"
 #include "api/video/video_rotation.h"
-#include "media/base/adapted_video_track_source.h"
 #include "rtc_base/checks.h"
 #include "rtc_base/logging.h"
 #include "rtc_base/thread.h"
diff --git a/sdk/android/src/jni/android_video_track_source.h b/sdk/android/src/jni/android_video_track_source.h
index ce0a0c1..bd5a8f9 100644
--- a/sdk/android/src/jni/android_video_track_source.h
+++ b/sdk/android/src/jni/android_video_track_source.h
@@ -19,7 +19,7 @@
 #include "api/environment/environment.h"
 #include "api/scoped_refptr.h"
 #include "api/task_queue/pending_task_safety_flag.h"
-#include "media/base/adapted_video_track_source.h"
+#include "api/video/adapted_video_track_source.h"
 #include "rtc_base/thread.h"
 #include "rtc_base/timestamp_aligner.h"
 #include "sdk/android/native_api/jni/scoped_java_ref.h"
diff --git a/sdk/objc/native/src/objc_video_track_source.h b/sdk/objc/native/src/objc_video_track_source.h
index 422b7a2..3ffe0d5 100644
--- a/sdk/objc/native/src/objc_video_track_source.h
+++ b/sdk/objc/native/src/objc_video_track_source.h
@@ -14,7 +14,7 @@
 #import "base/RTCVideoCapturer.h"
 
 #include "api/environment/environment.h"
-#include "media/base/adapted_video_track_source.h"
+#include "api/video/adapted_video_track_source.h"
 #include "rtc_base/timestamp_aligner.h"
 #include "sdk/objc/base/RTCMacros.h"
 
diff --git a/test/BUILD.gn b/test/BUILD.gn
index 9fb3850..ec4bbb8 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -119,10 +119,10 @@
   ]
   deps = [
     "../api:scoped_refptr",
+    "../api/video:video_adapter",
+    "../api/video:video_broadcaster",
     "../api/video:video_frame",
     "../api/video:video_rtp_headers",
-    "../media:video_adapter",
-    "../media:video_broadcaster",
     "../rtc_base:macromagic",
     "../rtc_base/synchronization:mutex",
   ]
diff --git a/test/test_video_capturer.h b/test/test_video_capturer.h
index 66f0c8b..ceefc9e 100644
--- a/test/test_video_capturer.h
+++ b/test/test_video_capturer.h
@@ -14,11 +14,11 @@
 #include <optional>
 #include <utility>
 
+#include "api/video/video_adapter.h"
+#include "api/video/video_broadcaster.h"
 #include "api/video/video_frame.h"
 #include "api/video/video_sink_interface.h"
 #include "api/video/video_source_interface.h"
-#include "media/base/video_adapter.h"
-#include "media/base/video_broadcaster.h"
 #include "rtc_base/synchronization/mutex.h"
 #include "rtc_base/thread_annotations.h"
 
diff --git a/unsafe_buffers_paths.txt b/unsafe_buffers_paths.txt
index 78b026e..cc0182b 100644
--- a/unsafe_buffers_paths.txt
+++ b/unsafe_buffers_paths.txt
@@ -55,6 +55,7 @@
 -api/video/test/nv12_buffer_unittest.cc
 -api/transport/stun.cc
 -api/transport/stun_unittest.cc
+-api/video/video_adapter_unittest.cc
 -api/video/video_bitrate_allocation.cc
 -api/video_codecs/h264_profile_level_id.cc
 -api/video_codecs/h265_profile_tier_level.cc
@@ -183,7 +184,6 @@
 -media/base/rtp_utils_unittest.cc
 -media/base/stream_params_unittest.cc
 -media/base/test_utils.h
--media/base/video_adapter_unittest.cc
 -media/engine/simulcast_encoder_adapter.cc
 -media/engine/simulcast_encoder_adapter_unittest.cc
 -media/engine/webrtc_media_engine.cc
diff --git a/video/BUILD.gn b/video/BUILD.gn
index 92bf7fa..09f0ecc 100644
--- a/video/BUILD.gn
+++ b/video/BUILD.gn
@@ -2051,6 +2051,7 @@
       "../api/video:render_resolution",
       "../api/video:resolution",
       "../api/video:video_adaptation",
+      "../api/video:video_adapter",
       "../api/video:video_bitrate_allocation",
       "../api/video:video_bitrate_allocator",
       "../api/video:video_bitrate_allocator_factory",
@@ -2070,7 +2071,6 @@
       "../common_video",
       "../common_video:corruption_score_calculator",
       "../media:rtc_audio_video",
-      "../media:video_adapter",
       "../modules/video_coding:video_codec_interface",
       "../modules/video_coding:video_coding_utility",
       "../modules/video_coding:webrtc_h264",
diff --git a/video/config/BUILD.gn b/video/config/BUILD.gn
index 0112dd8..3f1ce41 100644
--- a/video/config/BUILD.gn
+++ b/video/config/BUILD.gn
@@ -21,6 +21,7 @@
     "../../api:field_trials_view",
     "../../api/units:data_rate",
     "../../api/video:resolution",
+    "../../api/video:video_adapter",
     "../../api/video:video_frame",
     "../../api/video_codecs:video_codecs_api",
     "../../call/adaptation:resource_adaptation",
diff --git a/video/config/encoder_stream_factory.cc b/video/config/encoder_stream_factory.cc
index dc961d3..85a360c 100644
--- a/video/config/encoder_stream_factory.cc
+++ b/video/config/encoder_stream_factory.cc
@@ -21,6 +21,7 @@
 #include "api/field_trials_view.h"
 #include "api/units/data_rate.h"
 #include "api/video/resolution.h"
+#include "api/video/video_adapter.h"
 #include "api/video/video_codec_type.h"
 #include "api/video/video_source_interface.h"
 #include "api/video_codecs/spatial_layer.h"
@@ -28,7 +29,6 @@
 #include "api/video_codecs/video_encoder.h"
 #include "call/adaptation/video_source_restrictions.h"
 #include "media/base/media_constants.h"
-#include "media/base/video_adapter.h"
 #include "modules/video_coding/codecs/vp9/svc_config.h"
 #include "modules/video_coding/utility/simulcast_utility.h"
 #include "rtc_base/checks.h"
diff --git a/video/video_stream_encoder_unittest.cc b/video/video_stream_encoder_unittest.cc
index ecbda56..b56d0ed 100644
--- a/video/video_stream_encoder_unittest.cc
+++ b/video/video_stream_encoder_unittest.cc
@@ -58,6 +58,7 @@
 #include "api/video/resolution.h"
 #include "api/video/video_adaptation_counters.h"
 #include "api/video/video_adaptation_reason.h"
+#include "api/video/video_adapter.h"
 #include "api/video/video_bitrate_allocation.h"
 #include "api/video/video_bitrate_allocator.h"
 #include "api/video/video_bitrate_allocator_factory.h"
@@ -84,7 +85,6 @@
 #include "call/adaptation/video_stream_adapter.h"
 #include "call/video_send_stream.h"
 #include "common_video/h264/h264_common.h"
-#include "media/base/video_adapter.h"
 #include "media/engine/webrtc_video_engine.h"
 #include "modules/video_coding/codecs/av1/libaom_av1_encoder.h"
 #include "modules/video_coding/codecs/h264/include/h264.h"