Commit a66879ef authored by Ilya Nikolaevskiy's avatar Ilya Nikolaevskiy Committed by Commit Bot

Add webrtc logging in WebrtcVideoFrameAdapter

Bug: webrtc:11461
Change-Id: Ia3eb4e99b70d3acdd4c0109f825cf6de45e7f0e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2119521Reviewed-by: default avatarFlorent Castelli <orphis@chromium.org>
Commit-Queue: Florent Castelli <orphis@chromium.org>
Auto-Submit: Ilya Nikolaevskiy <ilnik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754908}
parent 5430effa
...@@ -461,7 +461,8 @@ void RTCVideoDecoderAdapter::OnOutput(scoped_refptr<media::VideoFrame> frame) { ...@@ -461,7 +461,8 @@ void RTCVideoDecoderAdapter::OnOutput(scoped_refptr<media::VideoFrame> frame) {
webrtc::VideoFrame::Builder() webrtc::VideoFrame::Builder()
.set_video_frame_buffer( .set_video_frame_buffer(
new rtc::RefCountedObject<blink::WebRtcVideoFrameAdapter>( new rtc::RefCountedObject<blink::WebRtcVideoFrameAdapter>(
std::move(frame))) std::move(frame),
WebRtcVideoFrameAdapter::LogStatus::kNoLogging))
.set_timestamp_rtp(static_cast<uint32_t>(timestamp.InMicroseconds())) .set_timestamp_rtp(static_cast<uint32_t>(timestamp.InMicroseconds()))
.set_timestamp_us(0) .set_timestamp_us(0)
.set_rotation(webrtc::kVideoRotation_0) .set_rotation(webrtc::kVideoRotation_0)
......
...@@ -67,12 +67,18 @@ gfx::Rect ScaleRectangle(const gfx::Rect& input_rect, ...@@ -67,12 +67,18 @@ gfx::Rect ScaleRectangle(const gfx::Rect& input_rect,
namespace blink { namespace blink {
const base::Feature kWebRtcLogWebRtcVideoFrameAdapter{
"WebRtcLogWebRtcVideoFrameAdapter", base::FEATURE_DISABLED_BY_DEFAULT};
WebRtcVideoTrackSource::WebRtcVideoTrackSource( WebRtcVideoTrackSource::WebRtcVideoTrackSource(
bool is_screencast, bool is_screencast,
absl::optional<bool> needs_denoising) absl::optional<bool> needs_denoising)
: AdaptedVideoTrackSource(/*required_alignment=*/1), : AdaptedVideoTrackSource(/*required_alignment=*/1),
is_screencast_(is_screencast), is_screencast_(is_screencast),
needs_denoising_(needs_denoising) { needs_denoising_(needs_denoising),
log_to_webrtc_(is_screencast &&
base::FeatureList::IsEnabled(
blink::kWebRtcLogWebRtcVideoFrameAdapter)) {
DETACH_FROM_THREAD(thread_checker_); DETACH_FROM_THREAD(thread_checker_);
} }
...@@ -325,7 +331,11 @@ void WebRtcVideoTrackSource::DeliverFrame( ...@@ -325,7 +331,11 @@ void WebRtcVideoTrackSource::DeliverFrame(
webrtc::VideoFrame::Builder frame_builder = webrtc::VideoFrame::Builder frame_builder =
webrtc::VideoFrame::Builder() webrtc::VideoFrame::Builder()
.set_video_frame_buffer( .set_video_frame_buffer(
new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(frame)) new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(
frame,
(log_to_webrtc_
? WebRtcVideoFrameAdapter::LogStatus::kLogToWebRtc
: WebRtcVideoFrameAdapter::LogStatus::kNoLogging)))
.set_rotation(webrtc::kVideoRotation_0) .set_rotation(webrtc::kVideoRotation_0)
.set_timestamp_us(timestamp_us); .set_timestamp_us(timestamp_us);
if (update_rect) { if (update_rect) {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_PEERCONNECTION_WEBRTC_VIDEO_TRACK_SOURCE_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_PEERCONNECTION_WEBRTC_VIDEO_TRACK_SOURCE_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_PEERCONNECTION_WEBRTC_VIDEO_TRACK_SOURCE_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_PEERCONNECTION_WEBRTC_VIDEO_TRACK_SOURCE_H_
#include "base/feature_list.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
#include "media/base/video_frame_pool.h" #include "media/base/video_frame_pool.h"
...@@ -14,6 +15,8 @@ ...@@ -14,6 +15,8 @@
namespace blink { namespace blink {
PLATFORM_EXPORT extern const base::Feature kWebRtcLogWebRtcVideoFrameAdapter;
// This class implements webrtc's VideoTrackSourceInterface. To pass frames down // This class implements webrtc's VideoTrackSourceInterface. To pass frames down
// the webrtc video pipeline, each received a media::VideoFrame is converted to // the webrtc video pipeline, each received a media::VideoFrame is converted to
// a webrtc::VideoFrame, taking any adaptation requested by downstream classes // a webrtc::VideoFrame, taking any adaptation requested by downstream classes
...@@ -80,6 +83,8 @@ class PLATFORM_EXPORT WebRtcVideoTrackSource ...@@ -80,6 +83,8 @@ class PLATFORM_EXPORT WebRtcVideoTrackSource
absl::optional<FrameAdaptationParams> absl::optional<FrameAdaptationParams>
custom_frame_adaptation_params_for_testing_; custom_frame_adaptation_params_for_testing_;
const bool log_to_webrtc_;
DISALLOW_COPY_AND_ASSIGN(WebRtcVideoTrackSource); DISALLOW_COPY_AND_ASSIGN(WebRtcVideoTrackSource);
}; };
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/stringprintf.h"
#include "third_party/blink/public/platform/modules/webrtc/webrtc_logging.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h" #include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/webrtc/common_video/include/video_frame_buffer.h" #include "third_party/webrtc/common_video/include/video_frame_buffer.h"
#include "third_party/webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "third_party/webrtc/common_video/libyuv/include/webrtc_libyuv.h"
...@@ -83,7 +85,8 @@ void IsValidFrame(const media::VideoFrame& frame) { ...@@ -83,7 +85,8 @@ void IsValidFrame(const media::VideoFrame& frame) {
} }
scoped_refptr<media::VideoFrame> ConstructI420VideoFrame( scoped_refptr<media::VideoFrame> ConstructI420VideoFrame(
const media::VideoFrame& source_frame) { const media::VideoFrame& source_frame,
blink::WebRtcVideoFrameAdapter::LogStatus log_to_webrtc) {
// NV12 is the only supported format. // NV12 is the only supported format.
DCHECK_EQ(source_frame.format(), media::PIXEL_FORMAT_NV12); DCHECK_EQ(source_frame.format(), media::PIXEL_FORMAT_NV12);
DCHECK_EQ(source_frame.storage_type(), DCHECK_EQ(source_frame.storage_type(),
...@@ -102,6 +105,22 @@ scoped_refptr<media::VideoFrame> ConstructI420VideoFrame( ...@@ -102,6 +105,22 @@ scoped_refptr<media::VideoFrame> ConstructI420VideoFrame(
((source_frame.visible_rect().x() / 2) * 2) + ((source_frame.visible_rect().x() / 2) * 2) +
((source_frame.visible_rect().y() / 2) * gmb->stride(1))); ((source_frame.visible_rect().y() / 2) * gmb->stride(1)));
if (log_to_webrtc ==
blink::WebRtcVideoFrameAdapter::LogStatus::kLogToWebRtc) {
blink::WebRtcLogMessage(base::StringPrintf(
"VFC::WebRtcVideoFrameAdapter : ConstructI420VideoFrame "
"pixel_format %d "
"natural_size %s coded_size %s visible_rect %s "
"source_plane_y %p source_plane_uv %p "
"source_stride_y %d, source_stride_uv %d "
"visible_y %p visible_uv %p",
static_cast<int>(source_frame.format()),
source_frame.natural_size().ToString().c_str(),
source_frame.coded_size().ToString().c_str(),
source_frame.visible_rect().ToString().c_str(), gmb->memory(0),
gmb->memory(1), gmb->stride(0), gmb->stride(1), src_y, src_uv));
}
// Convert to I420 and scale to the natural size specified in |source_frame|. // Convert to I420 and scale to the natural size specified in |source_frame|.
scoped_refptr<media::VideoFrame> i420_frame = media::VideoFrame::CreateFrame( scoped_refptr<media::VideoFrame> i420_frame = media::VideoFrame::CreateFrame(
media::PIXEL_FORMAT_I420, source_frame.natural_size(), media::PIXEL_FORMAT_I420, source_frame.natural_size(),
...@@ -131,8 +150,9 @@ scoped_refptr<media::VideoFrame> ConstructI420VideoFrame( ...@@ -131,8 +150,9 @@ scoped_refptr<media::VideoFrame> ConstructI420VideoFrame(
namespace blink { namespace blink {
WebRtcVideoFrameAdapter::WebRtcVideoFrameAdapter( WebRtcVideoFrameAdapter::WebRtcVideoFrameAdapter(
scoped_refptr<media::VideoFrame> frame) scoped_refptr<media::VideoFrame> frame,
: frame_(std::move(frame)) {} LogStatus log_to_webrtc)
: frame_(std::move(frame)), log_to_webrtc_(log_to_webrtc) {}
WebRtcVideoFrameAdapter::~WebRtcVideoFrameAdapter() {} WebRtcVideoFrameAdapter::~WebRtcVideoFrameAdapter() {}
...@@ -158,8 +178,12 @@ rtc::scoped_refptr<webrtc::I420BufferInterface> ...@@ -158,8 +178,12 @@ rtc::scoped_refptr<webrtc::I420BufferInterface>
WebRtcVideoFrameAdapter::CreateFrameAdapter() const { WebRtcVideoFrameAdapter::CreateFrameAdapter() const {
if (frame_->storage_type() == if (frame_->storage_type() ==
media::VideoFrame::StorageType::STORAGE_GPU_MEMORY_BUFFER) { media::VideoFrame::StorageType::STORAGE_GPU_MEMORY_BUFFER) {
auto i420_frame = ConstructI420VideoFrame(*frame_); auto i420_frame = ConstructI420VideoFrame(*frame_, log_to_webrtc_);
if (!i420_frame) { if (!i420_frame) {
if (log_to_webrtc_ == LogStatus::kLogToWebRtc) {
blink::WebRtcLogMessage(
"VFC::WebRtcVideoFrameAdapter couldn't contruct I420 frame");
}
return new rtc::RefCountedObject< return new rtc::RefCountedObject<
FrameAdapter<webrtc::I420BufferInterface>>( FrameAdapter<webrtc::I420BufferInterface>>(
media::VideoFrame::CreateColorFrame(frame_->natural_size(), 0u, 0x80, media::VideoFrame::CreateColorFrame(frame_->natural_size(), 0u, 0x80,
...@@ -188,7 +212,29 @@ WebRtcVideoFrameAdapter::CreateFrameAdapter() const { ...@@ -188,7 +212,29 @@ WebRtcVideoFrameAdapter::CreateFrameAdapter() const {
} }
IsValidFrame(*frame_); IsValidFrame(*frame_);
if (log_to_webrtc_ == LogStatus::kLogToWebRtc) {
blink::WebRtcLogMessage(base::StringPrintf(
"VFC::WebRtcVideoFrameAdapter created I420 adapter: "
"natural_size %s coded_size %s visible_rect %s "
"PlaneY %p PlaneU %p PlaneY %p StrideY %d StrideU %d StrideY %d ",
frame_->natural_size().ToString().c_str(),
frame_->coded_size().ToString().c_str(),
frame_->visible_rect().ToString().c_str(),
frame_->visible_data(media::VideoFrame::kYPlane),
frame_->visible_data(media::VideoFrame::kUPlane),
frame_->visible_data(media::VideoFrame::kVPlane),
frame_->stride(media::VideoFrame::kYPlane),
frame_->stride(media::VideoFrame::kUPlane),
frame_->stride(media::VideoFrame::kVPlane)));
}
if (media::PIXEL_FORMAT_I420A == frame_->format()) { if (media::PIXEL_FORMAT_I420A == frame_->format()) {
if (log_to_webrtc_ == LogStatus::kLogToWebRtc) {
blink::WebRtcLogMessage(base::StringPrintf(
"VFC::WebRtcVideoFrameAdapter pixel format is I420A. "
"PlaneA %p StrideA %d",
frame_->visible_data(media::VideoFrame::kAPlane),
frame_->stride(media::VideoFrame::kAPlane)));
}
return new rtc::RefCountedObject< return new rtc::RefCountedObject<
FrameAdapterWithA<webrtc::I420ABufferInterface>>(frame_); FrameAdapterWithA<webrtc::I420ABufferInterface>>(frame_);
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "third_party/webrtc/api/video/video_frame_buffer.h" #include "third_party/webrtc/api/video/video_frame_buffer.h"
namespace blink { namespace blink {
// Thin adapter from media::VideoFrame to webrtc::VideoFrameBuffer. This // Thin adapter from media::VideoFrame to webrtc::VideoFrameBuffer. This
// implementation is read-only and will return null if trying to get a // implementation is read-only and will return null if trying to get a
// non-const pointer to the pixel data. This object will be accessed from // non-const pointer to the pixel data. This object will be accessed from
...@@ -19,7 +20,10 @@ namespace blink { ...@@ -19,7 +20,10 @@ namespace blink {
class PLATFORM_EXPORT WebRtcVideoFrameAdapter class PLATFORM_EXPORT WebRtcVideoFrameAdapter
: public webrtc::VideoFrameBuffer { : public webrtc::VideoFrameBuffer {
public: public:
explicit WebRtcVideoFrameAdapter(scoped_refptr<media::VideoFrame> frame); enum class LogStatus { kNoLogging, kLogToWebRtc };
WebRtcVideoFrameAdapter(scoped_refptr<media::VideoFrame> frame,
LogStatus log_to_webrtc);
scoped_refptr<media::VideoFrame> getMediaVideoFrame() const { return frame_; } scoped_refptr<media::VideoFrame> getMediaVideoFrame() const { return frame_; }
...@@ -41,6 +45,8 @@ class PLATFORM_EXPORT WebRtcVideoFrameAdapter ...@@ -41,6 +45,8 @@ class PLATFORM_EXPORT WebRtcVideoFrameAdapter
mutable rtc::scoped_refptr<webrtc::I420BufferInterface> frame_adapter_; mutable rtc::scoped_refptr<webrtc::I420BufferInterface> frame_adapter_;
scoped_refptr<media::VideoFrame> frame_; scoped_refptr<media::VideoFrame> frame_;
const LogStatus log_to_webrtc_;
}; };
} // namespace blink } // namespace blink
......
...@@ -25,7 +25,8 @@ TEST(WebRtcVideoFrameAdapterTest, WidthAndHeight) { ...@@ -25,7 +25,8 @@ TEST(WebRtcVideoFrameAdapterTest, WidthAndHeight) {
media::VideoFrame::STORAGE_OWNED_MEMORY); media::VideoFrame::STORAGE_OWNED_MEMORY);
rtc::scoped_refptr<webrtc::VideoFrameBuffer> owned_memory_frame_adapter( rtc::scoped_refptr<webrtc::VideoFrameBuffer> owned_memory_frame_adapter(
new rtc::RefCountedObject<WebRtcVideoFrameAdapter>( new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(
std::move(owned_memory_frame))); std::move(owned_memory_frame),
WebRtcVideoFrameAdapter::LogStatus::kNoLogging));
EXPECT_EQ(owned_memory_frame_adapter->width(), kVisibleRect.width()); EXPECT_EQ(owned_memory_frame_adapter->width(), kVisibleRect.width());
EXPECT_EQ(owned_memory_frame_adapter->height(), kVisibleRect.height()); EXPECT_EQ(owned_memory_frame_adapter->height(), kVisibleRect.height());
...@@ -35,7 +36,9 @@ TEST(WebRtcVideoFrameAdapterTest, WidthAndHeight) { ...@@ -35,7 +36,9 @@ TEST(WebRtcVideoFrameAdapterTest, WidthAndHeight) {
CreateTestFrame(kCodedSize, kVisibleRect, kNaturalSize, CreateTestFrame(kCodedSize, kVisibleRect, kNaturalSize,
media::VideoFrame::STORAGE_GPU_MEMORY_BUFFER); media::VideoFrame::STORAGE_GPU_MEMORY_BUFFER);
rtc::scoped_refptr<webrtc::VideoFrameBuffer> gmb_frame_adapter( rtc::scoped_refptr<webrtc::VideoFrameBuffer> gmb_frame_adapter(
new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(std::move(gmb_frame))); new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(
std::move(gmb_frame),
WebRtcVideoFrameAdapter::LogStatus::kNoLogging));
EXPECT_EQ(gmb_frame_adapter->width(), kNaturalSize.width()); EXPECT_EQ(gmb_frame_adapter->width(), kNaturalSize.width());
EXPECT_EQ(gmb_frame_adapter->height(), kNaturalSize.height()); EXPECT_EQ(gmb_frame_adapter->height(), kNaturalSize.height());
} }
...@@ -52,7 +55,9 @@ TEST(WebRtcVideoFrameAdapterTest, ToI420DownScale) { ...@@ -52,7 +55,9 @@ TEST(WebRtcVideoFrameAdapterTest, ToI420DownScale) {
// The adapter should report width and height from the natural size for // The adapter should report width and height from the natural size for
// VideoFrame backed by GpuMemoryBuffer. // VideoFrame backed by GpuMemoryBuffer.
rtc::scoped_refptr<webrtc::VideoFrameBuffer> gmb_frame_adapter( rtc::scoped_refptr<webrtc::VideoFrameBuffer> gmb_frame_adapter(
new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(std::move(gmb_frame))); new rtc::RefCountedObject<WebRtcVideoFrameAdapter>(
std::move(gmb_frame),
WebRtcVideoFrameAdapter::LogStatus::kNoLogging));
EXPECT_EQ(gmb_frame_adapter->width(), kNaturalSize.width()); EXPECT_EQ(gmb_frame_adapter->width(), kNaturalSize.width());
EXPECT_EQ(gmb_frame_adapter->height(), kNaturalSize.height()); EXPECT_EQ(gmb_frame_adapter->height(), kNaturalSize.height());
......
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