Commit 7002a191 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Onion soup content/renderer/media/webrtc/rtc_video_encoder.cc|h

This is phase 1.7 on the design document [1].

[1] https://docs.google.com/document/d/1AJKVA5U4nDkyDB9p4ROrggWXadCxyy-grKaE9KS5vOU/

Files were move to renderer/platform/peerconnection directly, and a
factory header was added (namely [2]), so that content/ continue to
access RTCVideoEncoder's functionality.

[2] //t_p/blink/public/platform/modules/peerconnection/web_rtc_video_encoder_factory.h

As part of the move to Blink, this CL also embeds the declaration of
base::Feature "kWebRtcScreenshareSwEncoding" into rtc_video_encoder.cc|h,
and remove the respective content declaration from [3].

[3] //content/public/common/content_features.cc|h

BUG=787254
R=guidou@chromium.org, haraken@chromium.org
TBR=kinuko@chromium.org

Change-Id: Ibf3bc012443afd9d2112ab88133b41b844f00fba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1775002
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarkylechar <kylechar@chromium.org>
Auto-Submit: Antonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#691600}
parent 02054ad7
......@@ -111,6 +111,7 @@ class OutputDevice;
}
namespace blink {
class RTCVideoDecoderAdapter;
class RTCVideoEncoder;
class SourceStream;
class VideoFrameResourceProvider;
class WorkerThread;
......@@ -147,7 +148,6 @@ class InProcessUtilityThread;
class NestedMessagePumpAndroid;
class RenderWidgetHostViewMac;
class RTCVideoDecoder;
class RTCVideoEncoder;
class SandboxHostLinux;
class ScopedAllowWaitForDebugURL;
class ServiceWorkerContextClient;
......@@ -460,12 +460,12 @@ class BASE_EXPORT ScopedAllowBaseSyncPrimitivesOutsideBlockingScope {
friend class base::ScopedAllowThreadRecallForStackSamplingProfiler;
friend class base::StackSamplingProfiler;
friend class blink::RTCVideoDecoderAdapter;
friend class blink::RTCVideoEncoder;
friend class cc::TileTaskManagerImpl;
friend class content::CategorizedWorkerPool;
friend class content::DesktopCaptureDevice;
friend class content::InProcessUtilityThread;
friend class content::RTCVideoDecoder;
friend class content::RTCVideoEncoder;
friend class content::SandboxHostLinux;
friend class content::ScopedAllowWaitForDebugURL;
friend class content::SynchronousCompositor;
......
......@@ -703,11 +703,6 @@ const base::Feature kWebRtcHWVP9Encoding {
const base::Feature kWebRtcMultiplexCodec{"WebRTC-MultiplexCodec",
base::FEATURE_DISABLED_BY_DEFAULT};
// Fallback from hardware encoder (if available) to software, for WebRTC
// screensharing that uses temporal scalability.
const base::Feature kWebRtcScreenshareSwEncoding{
"WebRtcScreenshareSwEncoding", base::FEATURE_DISABLED_BY_DEFAULT};
// Use GpuMemoryBuffer backed VideoFrames in media streams.
const base::Feature kWebRtcUseGpuMemoryBufferVideoFrames{
"WebRTC-UseGpuMemoryBufferVideoFrames", base::FEATURE_ENABLED_BY_DEFAULT};
......
......@@ -145,7 +145,6 @@ CONTENT_EXPORT extern const base::Feature kWebRtcHWH264Encoding;
CONTENT_EXPORT extern const base::Feature kWebRtcHWVP8Encoding;
CONTENT_EXPORT extern const base::Feature kWebRtcHWVP9Encoding;
CONTENT_EXPORT extern const base::Feature kWebRtcMultiplexCodec;
CONTENT_EXPORT extern const base::Feature kWebRtcScreenshareSwEncoding;
CONTENT_EXPORT extern const base::Feature kWebRtcUseGpuMemoryBufferVideoFrames;
CONTENT_EXPORT extern const base::Feature kWebRtcHideLocalIpsWithMdns;
CONTENT_EXPORT extern const base::Feature kWebUsb;
......
......@@ -220,8 +220,6 @@ target(link_target_type, "renderer") {
"media/webrtc/rtc_rtp_transceiver.h",
"media/webrtc/rtc_video_decoder_factory.cc",
"media/webrtc/rtc_video_decoder_factory.h",
"media/webrtc/rtc_video_encoder.cc",
"media/webrtc/rtc_video_encoder.h",
"media/webrtc/rtc_video_encoder_factory.cc",
"media/webrtc/rtc_video_encoder_factory.h",
"media/webrtc/stun_field_trial.cc",
......
......@@ -12,10 +12,11 @@
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/feature_h264_with_openh264_ffmpeg.h"
#include "content/renderer/media/webrtc/rtc_video_encoder.h"
#include "media/media_buildflags.h"
#include "media/video/gpu_video_accelerator_factories.h"
#include "third_party/blink/public/platform/modules/peerconnection/web_rtc_video_encoder_factory.h"
#include "third_party/webrtc/api/video_codecs/sdp_video_format.h"
#include "third_party/webrtc/api/video_codecs/video_encoder.h"
#include "third_party/webrtc/common_video/h264/profile_level_id.h"
#include "third_party/webrtc/media/base/codec.h"
......@@ -126,7 +127,7 @@ RTCVideoEncoderFactory::CreateVideoEncoder(
const webrtc::SdpVideoFormat& format) {
for (size_t i = 0; i < supported_formats_.size(); ++i) {
if (IsSameFormat(format, supported_formats_[i])) {
return std::make_unique<RTCVideoEncoder>(profiles_[i], gpu_factories_);
return blink::CreateRTCVideoEncoder(profiles_[i], gpu_factories_);
}
}
return nullptr;
......
......@@ -1941,7 +1941,6 @@ test("content_unittests") {
"../renderer/media/webrtc/rtc_rtp_receiver_unittest.cc",
"../renderer/media/webrtc/rtc_rtp_sender_unittest.cc",
"../renderer/media/webrtc/rtc_rtp_transceiver_unittest.cc",
"../renderer/media/webrtc/rtc_video_encoder_unittest.cc",
"../renderer/media/webrtc/stun_field_trial_unittest.cc",
"../renderer/media/webrtc/task_queue_factory_unittest.cc",
"../renderer/media/webrtc/transceiver_state_surfacer_unittest.cc",
......
......@@ -158,6 +158,7 @@ source_set("blink_headers") {
"platform/modules/mediastream/webrtc_uma_histograms.h",
"platform/modules/peerconnection/audio_codec_factory.h",
"platform/modules/peerconnection/rtc_event_log_output_sink.h",
"platform/modules/peerconnection/web_rtc_video_encoder_factory.h",
"platform/modules/peerconnection/web_rtc_video_frame_adapter_factory.h",
"platform/modules/remoteplayback/web_remote_playback_client.h",
"platform/modules/service_worker/web_service_worker_error.h",
......
include_rules = [
"+media/base/video_codecs.h",
]
// Copyright 2019 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 THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_PEERCONNECTION_WEB_RTC_VIDEO_ENCODER_FACTORY_H_
#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_PEERCONNECTION_WEB_RTC_VIDEO_ENCODER_FACTORY_H_
#include <memory>
#include "media/base/video_codecs.h"
#include "third_party/blink/public/platform/web_common.h"
namespace webrtc {
class VideoEncoder;
}
namespace media {
class GpuVideoAcceleratorFactories;
}
namespace blink {
// TODO(crbug.com/787254): Remove this API when its clients are Onion souped.
BLINK_PLATFORM_EXPORT std::unique_ptr<webrtc::VideoEncoder>
CreateRTCVideoEncoder(media::VideoCodecProfile profile,
media::GpuVideoAcceleratorFactories* gpu_factories);
} // namespace blink
#endif // THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_PEERCONNECTION_WEB_RTC_VIDEO_ENCODER_FACTORY_H_
......@@ -1240,6 +1240,8 @@ jumbo_component("platform") {
"peerconnection/rtc_stats_response_base.h",
"peerconnection/rtc_video_decoder_adapter.cc",
"peerconnection/rtc_video_decoder_adapter.h",
"peerconnection/rtc_video_encoder.cc",
"peerconnection/rtc_video_encoder.h",
"peerconnection/rtc_void_request.h",
"prerender.cc",
"prerender.h",
......@@ -1461,6 +1463,7 @@ jumbo_component("platform") {
"//third_party/webrtc/api/audio_codecs/opus:audio_decoder_opus",
"//third_party/webrtc/api/audio_codecs/opus:audio_encoder_multiopus",
"//third_party/webrtc/api/audio_codecs/opus:audio_encoder_opus",
"//third_party/webrtc/modules/video_coding:webrtc_h264",
"//third_party/webrtc/p2p:rtc_p2p",
"//third_party/webrtc_overrides:init_webrtc",
"//third_party/zlib/google:compression_utils",
......@@ -1795,6 +1798,7 @@ jumbo_source_set("blink_platform_unittests_sources") {
"mojo/string16_mojom_traits_test.cc",
"peerconnection/rtc_stats_test.cc",
"peerconnection/rtc_video_decoder_adapter_test.cc",
"peerconnection/rtc_video_encoder_test.cc",
"text/bidi_resolver_test.cc",
"text/bidi_test_harness.h",
"text/capitalize_test.cc",
......
......@@ -11,6 +11,8 @@ include_rules = [
"+media/base",
"+media/video/gpu_video_accelerator_factories.h",
"+media/video/video_decode_accelerator.h",
"+media/video/h264_parser.h",
"+media/video/video_encode_accelerator.h",
"+third_party/blink/renderer/platform/bindings/script_wrappable.h",
"+third_party/blink/renderer/platform/heap",
"+third_party/blink/renderer/platform/platform_export.h",
......@@ -19,9 +21,10 @@ include_rules = [
]
specific_include_rules = {
"rtc_video_decoder_adapter_test\.cc": [
".*_test\.cc": [
"+base/threading/thread.h",
"+gpu/command_buffer/common/mailbox.h",
"+media/video/mock_gpu_video_accelerator_factories.h",
"+media/video/mock_video_encode_accelerator.h",
],
}
......@@ -2,9 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/media/webrtc/rtc_video_encoder.h"
#include <string.h>
#include "third_party/blink/renderer/platform/peerconnection/rtc_video_encoder.h"
#include <algorithm>
#include <memory>
......@@ -25,8 +23,6 @@
#include "base/threading/thread_restrictions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "media/base/bind_to_current_loop.h"
#include "media/base/bitstream_buffer.h"
#include "media/base/video_bitrate_allocation.h"
......@@ -36,13 +32,15 @@
#include "media/video/h264_parser.h"
#include "media/video/video_encode_accelerator.h"
#include "mojo/public/cpp/base/shared_memory_utils.h"
#include "third_party/blink/public/platform/modules/peerconnection/web_rtc_video_encoder_factory.h"
#include "third_party/blink/public/platform/modules/webrtc/webrtc_video_frame_adapter.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/libyuv/include/libyuv.h"
#include "third_party/webrtc/modules/video_coding/codecs/h264/include/h264.h"
#include "third_party/webrtc/modules/video_coding/include/video_error_codes.h"
#include "third_party/webrtc/rtc_base/time_utils.h"
namespace content {
namespace blink {
namespace {
......@@ -76,7 +74,8 @@ webrtc::VideoCodecType ProfileToWebRtcVideoCodecType(
// Each entry specifies the offset and length (excluding start code) of a NALU.
// Returns true if successful.
bool GetRTPFragmentationHeaderH264(webrtc::RTPFragmentationHeader* header,
const uint8_t* data, uint32_t length) {
const uint8_t* data,
uint32_t length) {
std::vector<media::H264NALU> nalu_vector;
if (!media::H264Parser::ParseNALUs(data, length, &nalu_vector)) {
// H264Parser::ParseNALUs() has logged the errors already.
......@@ -105,6 +104,15 @@ void RecordInitEncodeUMA(int32_t init_retval,
} // namespace
namespace features {
// Fallback from hardware encoder (if available) to software, for WebRTC
// screensharing that uses temporal scalability.
const base::Feature kWebRtcScreenshareSwEncoding{
"WebRtcScreenshareSwEncoding", base::FEATURE_DISABLED_BY_DEFAULT};
} // namespace features
// This private class of RTCVideoEncoder does the actual work of communicating
// with a media::VideoEncodeAccelerator for handling video encoding. It can
// be created on any thread, but should subsequently be posted to (and Destroy()
......@@ -186,7 +194,7 @@ class RTCVideoEncoder::Impl
// Logs the |error| and |str| sent from |location| and NotifyError()s forward.
void LogAndNotifyError(const base::Location& location,
const std::string& str,
const String& str,
media::VideoEncodeAccelerator::Error error);
// Perform encoding on an input frame from the input queue.
......@@ -255,6 +263,9 @@ class RTCVideoEncoder::Impl
// Shared memory buffers for input/output with the VEA. The input buffers may
// be referred to by a VideoFrame, so they are wrapped in a unique_ptr to have
// a stable memory location. That is not necessary for the output buffers.
//
// TODO(crbug.com/787254): Replace the use of std::vector by WTF::Vector here
// and where else possible in this file.
std::vector<std::unique_ptr<std::pair<base::UnsafeSharedMemoryRegion,
base::WritableSharedMemoryMapping>>>
input_buffers_;
......@@ -468,7 +479,7 @@ void RTCVideoEncoder::Impl::SetStatus(int32_t status) {
void RTCVideoEncoder::Impl::RecordTimestampMatchUMA() const {
UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderTimestampMatchSuccess",
failed_timestamp_match_ == false);
!failed_timestamp_match_);
}
void RTCVideoEncoder::Impl::RequireBitstreamBuffers(
......@@ -628,11 +639,13 @@ void RTCVideoEncoder::Impl::NotifyError(
SignalAsyncWaiter(retval);
}
RTCVideoEncoder::Impl::~Impl() { DCHECK(!video_encoder_); }
RTCVideoEncoder::Impl::~Impl() {
DCHECK(!video_encoder_);
}
void RTCVideoEncoder::Impl::LogAndNotifyError(
const base::Location& location,
const std::string& str,
const String& str,
media::VideoEncodeAccelerator::Error error) {
static const char* const kErrorNames[] = {
"kIllegalStateError", "kInvalidArgumentError", "kPlatformFailureError"};
......@@ -719,6 +732,8 @@ void RTCVideoEncoder::Impl::EncodeOneFrame() {
return;
}
}
// TODO(crbug.com/787254): Replace the use of base::Bind by WTF::Bind here
// and where else possible in this file.
frame->AddDestructionObserver(media::BindToCurrentLoop(base::BindOnce(
&RTCVideoEncoder::Impl::EncodeFrameFinished, this, index)));
if (!failed_timestamp_match_) {
......@@ -861,6 +876,12 @@ void RTCVideoEncoder::Impl::ReturnEncodedImage(
UseOutputBitstreamBufferId(bitstream_buffer_id);
}
std::unique_ptr<webrtc::VideoEncoder> CreateRTCVideoEncoder(
media::VideoCodecProfile profile,
media::GpuVideoAcceleratorFactories* gpu_factories) {
return std::make_unique<RTCVideoEncoder>(profile, gpu_factories);
}
RTCVideoEncoder::RTCVideoEncoder(
media::VideoCodecProfile profile,
media::GpuVideoAcceleratorFactories* gpu_factories)
......@@ -1030,4 +1051,4 @@ webrtc::VideoEncoder::EncoderInfo RTCVideoEncoder::GetEncoderInfo() const {
return info;
}
} // namespace content
} // namespace blink
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_RENDERER_MEDIA_WEBRTC_RTC_VIDEO_ENCODER_H_
#define CONTENT_RENDERER_MEDIA_WEBRTC_RTC_VIDEO_ENCODER_H_
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_PEERCONNECTION_RTC_VIDEO_ENCODER_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_PEERCONNECTION_RTC_VIDEO_ENCODER_H_
#include <stddef.h>
#include <stdint.h>
......@@ -11,13 +11,14 @@
#include <memory>
#include <vector>
#include "base/feature_list.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h"
#include "base/time/time.h"
#include "content/common/content_export.h"
#include "media/base/video_decoder_config.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/webrtc/api/video/video_bitrate_allocation.h"
#include "third_party/webrtc/modules/video_coding/include/video_codec_interface.h"
#include "ui/gfx/geometry/size.h"
......@@ -30,7 +31,11 @@ namespace media {
class GpuVideoAcceleratorFactories;
} // namespace media
namespace content {
namespace blink {
namespace features {
PLATFORM_EXPORT extern const base::Feature kWebRtcScreenshareSwEncoding;
}
// RTCVideoEncoder uses a media::VideoEncodeAccelerator to implement a
// webrtc::VideoEncoder class for WebRTC. Internally, VEA methods are
......@@ -39,7 +44,7 @@ namespace content {
// the media thread. RTCVideoEncoder is sychronized by webrtc::VideoSender.
// webrtc::VideoEncoder methods do not run concurrently. RtcVideoEncoder needs
// to synchronize RegisterEncodeCompleteCallback and encode complete callback.
class CONTENT_EXPORT RTCVideoEncoder : public webrtc::VideoEncoder {
class PLATFORM_EXPORT RTCVideoEncoder : public webrtc::VideoEncoder {
public:
RTCVideoEncoder(media::VideoCodecProfile profile,
media::GpuVideoAcceleratorFactories* gpu_factories);
......@@ -78,6 +83,6 @@ class CONTENT_EXPORT RTCVideoEncoder : public webrtc::VideoEncoder {
DISALLOW_COPY_AND_ASSIGN(RTCVideoEncoder);
};
} // namespace content
} // namespace blink
#endif // CONTENT_RENDERER_MEDIA_WEBRTC_RTC_VIDEO_ENCODER_H_
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_PEERCONNECTION_RTC_VIDEO_ENCODER_H_
......@@ -8,10 +8,10 @@
#include "base/single_thread_task_runner.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/thread.h"
#include "content/renderer/media/webrtc/rtc_video_encoder.h"
#include "media/video/mock_gpu_video_accelerator_factories.h"
#include "media/video/mock_video_encode_accelerator.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/platform/peerconnection/rtc_video_encoder.h"
#include "third_party/libyuv/include/libyuv/planar_functions.h"
#include "third_party/webrtc/api/video/i420_buffer.h"
#include "third_party/webrtc/api/video_codecs/video_encoder.h"
......@@ -26,16 +26,16 @@ using ::testing::SaveArg;
using ::testing::Values;
using ::testing::WithArgs;
namespace content {
namespace blink {
namespace {
const int kInputFrameFillY = 12;
const int kInputFrameFillU = 23;
const int kInputFrameFillV = 34;
const unsigned short kInputFrameHeight = 234;
const unsigned short kInputFrameWidth = 345;
const unsigned short kStartBitrate = 100;
const uint16_t kInputFrameHeight = 234;
const uint16_t kInputFrameWidth = 345;
const uint16_t kStartBitrate = 100;
class EncodedImageCallbackWrapper : public webrtc::EncodedImageCallback {
public:
......@@ -344,4 +344,4 @@ TEST_F(RTCVideoEncoderTest, PreserveTimestamps) {
rtc_encoder_->Encode(rtc_frame, &frame_types));
}
} // namespace content
} // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment