Surface the SetMetadata() method so that Chromium can use it.

RTPVideoHeader is changed to non-const to allow modifying it. We want
to do this when implementing setMetadata() in JavaScript or when
refactoring clone() as "construct + set bytes + setMetadata".

Unblocks
https://chromium-review.googlesource.com/c/chromium/src/+/4164979.

Bug: webrtc:14709
Change-Id: I6089df9c03e9aa33feeb0830dd240dd456cb565e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/290981
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39113}
This commit is contained in:
Henrik Boström 2023-01-16 10:41:28 +01:00 committed by WebRTC LUCI CQ
parent 6afa92ab20
commit 3dd73ae6f4
5 changed files with 28 additions and 2 deletions

View File

@ -62,6 +62,9 @@ class TransformableVideoFrameInterface : public TransformableFrameInterface {
virtual std::vector<uint8_t> GetAdditionalData() const = 0;
virtual const VideoFrameMetadata& GetMetadata() const = 0;
// TODO(https://crbug.com/webrtc/14709): Make pure virtual when Chromium MOCK
// has implemented this.
virtual void SetMetadata(const VideoFrameMetadata&) {}
};
// Extends the TransformableFrameInterface to expose audio-specific information.

View File

@ -31,6 +31,10 @@ class MockTransformableVideoFrame
GetMetadata,
(),
(const, override));
MOCK_METHOD(void,
SetMetadata,
(const webrtc::VideoFrameMetadata&),
(override));
};
} // namespace webrtc

View File

@ -48,6 +48,10 @@ class MockTransformableVideoFrame
GetMetadata,
(),
(const, override));
MOCK_METHOD(void,
SetMetadata,
(const webrtc::VideoFrameMetadata&),
(override));
};
TEST(FrameTransformerFactory, CloneVideoFrame) {

View File

@ -69,6 +69,12 @@ class TransformableVideoSenderFrame : public TransformableVideoFrameInterface {
}
const VideoFrameMetadata& GetMetadata() const override { return metadata_; }
void SetMetadata(const VideoFrameMetadata& metadata) override {
header_.SetFromMetadata(metadata);
// We have to keep a local copy because GetMetadata() has to return a
// reference.
metadata_ = header_.GetAsMetadata();
}
const RTPVideoHeader& GetHeader() const { return header_; }
uint8_t GetPayloadType() const override { return payload_type_; }
@ -83,8 +89,12 @@ class TransformableVideoSenderFrame : public TransformableVideoFrameInterface {
private:
rtc::scoped_refptr<EncodedImageBufferInterface> encoded_data_;
const RTPVideoHeader header_;
const VideoFrameMetadata metadata_;
RTPVideoHeader header_;
// This is a copy of `header_.GetAsMetadata()`, only needed because the
// interface says GetMetadata() must return a const ref rather than a value.
// TODO(crbug.com/webrtc/14709): Change the interface and delete this variable
// to reduce risk of it getting out-of-sync with `header_.GetAsMetadata()`.
VideoFrameMetadata metadata_;
const VideoFrameType frame_type_;
const uint8_t payload_type_;
const absl::optional<VideoCodecType> codec_type_ = absl::nullopt;

View File

@ -15,6 +15,7 @@
#include "absl/memory/memory.h"
#include "modules/rtp_rtcp/source/rtp_descriptor_authentication.h"
#include "rtc_base/checks.h"
#include "rtc_base/thread.h"
namespace webrtc {
@ -53,6 +54,10 @@ class TransformableVideoReceiverFrame
}
const VideoFrameMetadata& GetMetadata() const override { return metadata_; }
void SetMetadata(const VideoFrameMetadata&) override {
RTC_DCHECK_NOTREACHED()
<< "TransformableVideoReceiverFrame::SetMetadata is not implemented";
}
std::unique_ptr<RtpFrameObject> ExtractFrame() && {
return std::move(frame_);