Skip to content

Commit

Permalink
[Cast Streaming] Split Cast streaming encoding out to a separate folder
Browse files Browse the repository at this point in the history
This moves encoding for Cast Streaming into media/cast/encoding and
separates it from the generic sender library.  This will facilitate
migration of the sender to libcast and future upstreaming of encoding
to libcast.

Bug: 1304256
Change-Id: Idc0dd6ecc157f052222054d04a0f71e862964c01
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3612383
Reviewed-by: Joe Downing <joedow@chromium.org>
Reviewed-by: Ryan Keane <rwkeane@google.com>
Commit-Queue: Mark Foltz <mfoltz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#997415}
  • Loading branch information
markafoltz authored and Chromium LUCI CQ committed Apr 28, 2022
1 parent 5dfbf40 commit 1f26acf
Show file tree
Hide file tree
Showing 74 changed files with 460 additions and 377 deletions.
1 change: 1 addition & 0 deletions components/mirroring/service/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ component("mirroring_service") {
"//media/capture:capture_base",
"//media/capture/mojom:video_capture",
"//media/cast:common",
"//media/cast:encoding",
"//media/cast:net",
"//media/cast:sender",
"//media/gpu",
Expand Down
2 changes: 1 addition & 1 deletion components/mirroring/service/remoting_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/default_tick_clock.h"
#include "base/time/time.h"
#include "media/cast/common/sender_encoded_frame.h"
#include "media/cast/constants.h"
#include "media/cast/sender/sender_encoded_frame.h"
#include "media/mojo/common/mojo_data_pipe_read_write.h"

namespace mirroring {
Expand Down
1 change: 1 addition & 0 deletions components/mirroring/service/remoting_sender_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/run_loop.h"
#include "base/test/task_environment.h"
#include "base/time/default_tick_clock.h"
#include "media/cast/common/encoded_frame.h"
#include "media/cast/constants.h"
#include "media/cast/net/cast_transport.h"
#include "media/cast/test/utility/default_config.h"
Expand Down
2 changes: 1 addition & 1 deletion components/mirroring/service/session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
#include "media/audio/audio_input_device.h"
#include "media/base/audio_capturer_source.h"
#include "media/base/bind_to_current_loop.h"
#include "media/cast/encoding/external_video_encoder.h"
#include "media/cast/net/cast_transport.h"
#include "media/cast/sender/audio_sender.h"
#include "media/cast/sender/external_video_encoder.h"
#include "media/cast/sender/video_sender.h"
#include "media/gpu/gpu_video_accelerator_util.h"
#include "media/mojo/clients/mojo_video_encode_accelerator.h"
Expand Down
111 changes: 66 additions & 45 deletions media/cast/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,25 @@ proto_library("logging_proto") {
# Common code shared by all cast components.
source_set("common") {
sources = [
"cast_callbacks.h",
"cast_config.cc",
"cast_config.h",
"cast_environment.cc",
"cast_environment.h",
"common/clock_drift_smoother.cc",
"common/clock_drift_smoother.h",
"common/encoded_frame.cc",
"common/encoded_frame.h",
"common/expanded_value_base.h",
"common/frame_id.cc",
"common/frame_id.h",
"common/rtp_time.cc",
"common/rtp_time.h",
"common/sender_encoded_frame.cc",
"common/sender_encoded_frame.h",
"common/transport_encryption_handler.cc",
"common/transport_encryption_handler.h",
"common/video_frame_factory.h",
"constants.h",
"logging/encoding_event_subscriber.cc",
"logging/encoding_event_subscriber.h",
Expand Down Expand Up @@ -118,49 +124,31 @@ source_set("net") {
public_deps = [ ":common" ]
}

source_set("sender") {
source_set("encoding") {
sources = [
"cast_sender.h",
"cast_sender_impl.cc",
"cast_sender_impl.h",
"sender/audio_encoder.cc",
"sender/audio_encoder.h",
"sender/audio_sender.cc",
"sender/audio_sender.h",
"sender/congestion_control.cc",
"sender/congestion_control.h",
"sender/external_video_encoder.cc",
"sender/external_video_encoder.h",
"sender/fake_software_video_encoder.cc",
"sender/fake_software_video_encoder.h",
"sender/frame_sender.cc",
"sender/frame_sender.h",
"sender/performance_metrics_overlay.cc",
"sender/performance_metrics_overlay.h",
"sender/sender_encoded_frame.cc",
"sender/sender_encoded_frame.h",
"sender/size_adaptable_video_encoder_base.cc",
"sender/size_adaptable_video_encoder_base.h",
"sender/software_video_encoder.h",
"sender/video_encoder.cc",
"sender/video_encoder.h",
"sender/video_encoder_impl.cc",
"sender/video_encoder_impl.h",
"sender/video_frame_factory.h",
"sender/video_sender.cc",
"sender/video_sender.h",
"sender/vpx_encoder.cc",
"sender/vpx_encoder.h",
"sender/vpx_quantizer_parser.cc",
"sender/vpx_quantizer_parser.h",
"encoding/audio_encoder.cc",
"encoding/audio_encoder.h",
"encoding/external_video_encoder.cc",
"encoding/external_video_encoder.h",
"encoding/fake_software_video_encoder.cc",
"encoding/fake_software_video_encoder.h",
"encoding/size_adaptable_video_encoder_base.cc",
"encoding/size_adaptable_video_encoder_base.h",
"encoding/software_video_encoder.h",
"encoding/video_encoder.cc",
"encoding/video_encoder.h",
"encoding/video_encoder_impl.cc",
"encoding/video_encoder_impl.h",
"encoding/vpx_encoder.cc",
"encoding/vpx_encoder.h",
"encoding/vpx_quantizer_parser.cc",
"encoding/vpx_quantizer_parser.h",
]

deps = [
":common",
":net",
"//base",
"//media",
"//media/capture:capture_base",
"//third_party/libaom:libaom_buildflags",
"//third_party/libvpx",
"//third_party/opus",
Expand All @@ -170,8 +158,8 @@ source_set("sender") {
# iOS and OS X encoders
if (is_apple) {
sources += [
"sender/h264_vt_encoder.cc",
"sender/h264_vt_encoder.h",
"encoding/h264_vt_encoder.cc",
"encoding/h264_vt_encoder.h",
]

frameworks = [
Expand All @@ -185,8 +173,8 @@ source_set("sender") {

if (enable_libaom) {
sources += [
"sender/av1_encoder.cc",
"sender/av1_encoder.h",
"encoding/av1_encoder.cc",
"encoding/av1_encoder.h",
]

deps += [ "//third_party/libaom" ]
Expand All @@ -197,6 +185,38 @@ source_set("sender") {
}
}

source_set("sender") {
sources = [
"cast_sender.h",
"cast_sender_impl.cc",
"cast_sender_impl.h",
"sender/audio_sender.cc",
"sender/audio_sender.h",
"sender/congestion_control.cc",
"sender/congestion_control.h",
"sender/frame_sender.cc",
"sender/frame_sender.h",
"sender/performance_metrics_overlay.cc",
"sender/performance_metrics_overlay.h",
"sender/video_sender.cc",
"sender/video_sender.h",
]

deps = [
":common",
":encoding",
":net",
"//base",
"//media",
"//media/capture:capture_base",
"//ui/gfx/geometry",
]

if (is_chromeos) {
deps += [ "//third_party/re2" ]
}
}

source_set("test_receiver") {
testonly = true
sources = [
Expand Down Expand Up @@ -299,6 +319,9 @@ test("cast_unittests") {
sources = [
"common/expanded_value_base_unittest.cc",
"common/rtp_time_unittest.cc",
"encoding/external_video_encoder_unittest.cc",
"encoding/video_encoder_unittest.cc",
"encoding/vpx_quantizer_parser_unittest.cc",
"logging/encoding_event_subscriber_unittest.cc",
"logging/receiver_time_offset_estimator_impl_unittest.cc",
"logging/simple_event_subscriber_unittest.cc",
Expand All @@ -314,6 +337,7 @@ test("cast_unittests") {

# TODO(jophba): The following two are test utility modules. Rename/move the
# files.
"encoding/audio_encoder_unittest.cc",
"net/rtcp/test_rtcp_packet_builder.cc",
"net/rtcp/test_rtcp_packet_builder.h",
"net/rtp/mock_rtp_payload_feedback.cc",
Expand All @@ -325,13 +349,9 @@ test("cast_unittests") {
"net/rtp/rtp_parser_unittest.cc",
"net/udp_packet_pipe_unittest.cc",
"net/udp_transport_unittest.cc",
"sender/audio_encoder_unittest.cc",
"sender/audio_sender_unittest.cc",
"sender/congestion_control_unittest.cc",
"sender/external_video_encoder_unittest.cc",
"sender/video_encoder_unittest.cc",
"sender/video_sender_unittest.cc",
"sender/vpx_quantizer_parser_unittest.cc",
"test/end2end_unittest.cc",
"test/receiver/audio_decoder_unittest.cc",
"test/receiver/cast_message_builder_unittest.cc",
Expand All @@ -346,6 +366,7 @@ test("cast_unittests") {

deps = [
":common",
":encoding",
":net",
":sender",
":test_receiver",
Expand All @@ -372,7 +393,7 @@ test("cast_unittests") {
}

if (is_apple) {
sources += [ "sender/h264_vt_encoder_unittest.cc" ]
sources += [ "encoding/h264_vt_encoder_unittest.cc" ]

deps += [ "//third_party/ffmpeg" ]
}
Expand Down
26 changes: 26 additions & 0 deletions media/cast/cast_callbacks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2022 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.

#ifndef MEDIA_CAST_CAST_CALLBACKS_H_
#define MEDIA_CAST_CAST_CALLBACKS_H_

#include "base/callback_forward.h"
#include "media/cast/constants.h"

namespace media {
namespace cast {

// Callback that is run to update the client with current status. This is used
// to allow the client to wait for asynchronous initialization to complete
// before sending frames, and also to be notified of any runtime errors that
// have halted the session.
using StatusChangeCallback = base::RepeatingCallback<void(OperationalStatus)>;

// The equivalent of StatusChangeCallback when only one change is expected.
using StatusChangeOnceCallback = base::OnceCallback<void(OperationalStatus)>;

} // namespace cast
} // namespace media

#endif // MEDIA_CAST_CAST_CALLBACKS_H_
10 changes: 1 addition & 9 deletions media/cast/cast_sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "base/time/time.h"
#include "media/base/audio_bus.h"
#include "media/base/video_frame.h"
#include "media/cast/cast_callbacks.h"
#include "media/cast/cast_config.h"
#include "media/cast/cast_environment.h"
#include "media/cast/constants.h"
Expand Down Expand Up @@ -76,15 +77,6 @@ class AudioFrameInput : public base::RefCountedThreadSafe<AudioFrameInput> {
friend class base::RefCountedThreadSafe<AudioFrameInput>;
};

// Callback that is run to update the client with current status. This is used
// to allow the client to wait for asynchronous initialization to complete
// before sending frames, and also to be notified of any runtime errors that
// have halted the session.
using StatusChangeCallback = base::RepeatingCallback<void(OperationalStatus)>;

// The equivalent of StatusChangeCallback when only one change is expected.
using StatusChangeOnceCallback = base::OnceCallback<void(OperationalStatus)>;

// All methods of CastSender must be called on the main thread.
// Provided CastTransport will also be called on the main thread.
class CastSender {
Expand Down
2 changes: 1 addition & 1 deletion media/cast/cast_sender_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "base/callback_helpers.h"
#include "base/logging.h"
#include "media/base/video_frame.h"
#include "media/cast/sender/video_frame_factory.h"
#include "media/cast/common/video_frame_factory.h"

namespace media {
namespace cast {
Expand Down
28 changes: 28 additions & 0 deletions media/cast/common/encoded_frame.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2022 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.

#include "media/cast/common/encoded_frame.h"

#include "base/logging.h"

namespace media {
namespace cast {

EncodedFrame::EncodedFrame()
: dependency(UNKNOWN_DEPENDENCY), new_playout_delay_ms(0) {}

EncodedFrame::~EncodedFrame() = default;

void EncodedFrame::CopyMetadataTo(EncodedFrame* dest) const {
DCHECK(dest);
dest->dependency = this->dependency;
dest->frame_id = this->frame_id;
dest->referenced_frame_id = this->referenced_frame_id;
dest->rtp_timestamp = this->rtp_timestamp;
dest->reference_time = this->reference_time;
dest->new_playout_delay_ms = this->new_playout_delay_ms;
}

} // namespace cast
} // namespace media
Loading

0 comments on commit 1f26acf

Please sign in to comment.