Introduce the TransformerHost interface
This is the first step in implementing custom codecs in SDP.
Bug: none
Change-Id: I7789478208a769eaefd58b410ae6f488c604594d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/348662
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Tony Herre <herre@google.com>
Cr-Commit-Position: refs/heads/main@{#42171}
diff --git a/api/frame_transformer_interface.h b/api/frame_transformer_interface.h
index 102ac33..d3d1541 100644
--- a/api/frame_transformer_interface.h
+++ b/api/frame_transformer_interface.h
@@ -120,6 +120,18 @@
~FrameTransformerInterface() override = default;
};
+// An interface implemented by classes that can host a transform.
+// Currently this is implemented by the RTCRtpSender and RTCRtpReceiver.
+class FrameTransformerHost {
+ public:
+ virtual ~FrameTransformerHost() {}
+ virtual void SetFrameTransformer(
+ rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) = 0;
+ // TODO: bugs.webrtc.org/15929 - To be added:
+ // virtual AddIncomingMediaType(RtpCodec codec) = 0;
+ // virtual AddOutgoingMediaType(RtpCodec codec) = 0;
+};
+
} // namespace webrtc
#endif // API_FRAME_TRANSFORMER_INTERFACE_H_
diff --git a/api/rtp_receiver_interface.cc b/api/rtp_receiver_interface.cc
index bc9aef5..ffa4216 100644
--- a/api/rtp_receiver_interface.cc
+++ b/api/rtp_receiver_interface.cc
@@ -38,7 +38,7 @@
return nullptr;
}
-void RtpReceiverInterface::SetDepacketizerToDecoderFrameTransformer(
+void RtpReceiverInterface::SetFrameTransformer(
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) {}
} // namespace webrtc
diff --git a/api/rtp_receiver_interface.h b/api/rtp_receiver_interface.h
index 0bf1af9..b1b36b5 100644
--- a/api/rtp_receiver_interface.h
+++ b/api/rtp_receiver_interface.h
@@ -15,8 +15,10 @@
#define API_RTP_RECEIVER_INTERFACE_H_
#include <string>
+#include <utility>
#include <vector>
+#include "absl/types/optional.h"
#include "api/crypto/frame_decryptor_interface.h"
#include "api/dtls_transport_interface.h"
#include "api/frame_transformer_interface.h"
@@ -44,7 +46,8 @@
virtual ~RtpReceiverObserverInterface() {}
};
-class RTC_EXPORT RtpReceiverInterface : public webrtc::RefCountInterface {
+class RTC_EXPORT RtpReceiverInterface : public webrtc::RefCountInterface,
+ public FrameTransformerHost {
public:
virtual rtc::scoped_refptr<MediaStreamTrackInterface> track() const = 0;
@@ -111,8 +114,17 @@
// Sets a frame transformer between the depacketizer and the decoder to enable
// client code to transform received frames according to their own processing
// logic.
+ // TODO: bugs.webrtc.org/15929 - add [[deprecated("Use SetFrameTransformer")]]
+ // when usage in Chrome is removed
virtual void SetDepacketizerToDecoderFrameTransformer(
- rtc::scoped_refptr<FrameTransformerInterface> frame_transformer);
+ rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) {
+ SetFrameTransformer(std::move(frame_transformer));
+ }
+
+ // Default implementation of SetFrameTransformer.
+ // TODO: bugs.webrtc.org/15929 - Make pure virtual.
+ void SetFrameTransformer(
+ rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) override;
protected:
~RtpReceiverInterface() override = default;
diff --git a/api/rtp_sender_interface.h b/api/rtp_sender_interface.h
index 7b8ab13..7d92c42 100644
--- a/api/rtp_sender_interface.h
+++ b/api/rtp_sender_interface.h
@@ -14,8 +14,10 @@
#ifndef API_RTP_SENDER_INTERFACE_H_
#define API_RTP_SENDER_INTERFACE_H_
+#include <cstdint>
#include <memory>
#include <string>
+#include <utility>
#include <vector>
#include "absl/functional/any_invocable.h"
@@ -36,7 +38,8 @@
using SetParametersCallback = absl::AnyInvocable<void(RTCError) &&>;
-class RTC_EXPORT RtpSenderInterface : public webrtc::RefCountInterface {
+class RTC_EXPORT RtpSenderInterface : public webrtc::RefCountInterface,
+ public FrameTransformerHost {
public:
// Returns true if successful in setting the track.
// Fails if an audio track is set on a video RtpSender, or vice-versa.
@@ -100,8 +103,12 @@
virtual rtc::scoped_refptr<FrameEncryptorInterface> GetFrameEncryptor()
const = 0;
+ // TODO: bugs.webrtc.org/15929 - add [[deprecated("Use SetFrameTransformer")]]
+ // when usage in Chrome is removed
virtual void SetEncoderToPacketizerFrameTransformer(
- rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) = 0;
+ rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) {
+ SetFrameTransformer(std::move(frame_transformer));
+ }
// Sets a user defined encoder selector.
// Overrides selector that is (optionally) provided by VideoEncoderFactory.
@@ -109,6 +116,11 @@
std::unique_ptr<VideoEncoderFactory::EncoderSelectorInterface>
encoder_selector) = 0;
+ // Default implementation of SetFrameTransformer.
+ // TODO: bugs.webrtc.org/15929 - remove when all implementations are good
+ void SetFrameTransformer(rtc::scoped_refptr<FrameTransformerInterface>
+ frame_transformer) override {}
+
protected:
~RtpSenderInterface() override = default;
};
diff --git a/api/test/mock_rtpsender.h b/api/test/mock_rtpsender.h
index 2211367..5a38d1d 100644
--- a/api/test/mock_rtpsender.h
+++ b/api/test/mock_rtpsender.h
@@ -63,7 +63,7 @@
(),
(const, override));
MOCK_METHOD(void,
- SetEncoderToPacketizerFrameTransformer,
+ SetFrameTransformer,
(rtc::scoped_refptr<FrameTransformerInterface>),
(override));
MOCK_METHOD(void,
diff --git a/pc/audio_rtp_receiver.cc b/pc/audio_rtp_receiver.cc
index 6e7ca6d..0f395a7 100644
--- a/pc/audio_rtp_receiver.cc
+++ b/pc/audio_rtp_receiver.cc
@@ -277,7 +277,7 @@
return media_channel_->GetSources(current_ssrc.value());
}
-void AudioRtpReceiver::SetDepacketizerToDecoderFrameTransformer(
+void AudioRtpReceiver::SetFrameTransformer(
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) {
RTC_DCHECK_RUN_ON(worker_thread_);
if (media_channel_) {
diff --git a/pc/audio_rtp_receiver.h b/pc/audio_rtp_receiver.h
index 36cbdff..d0433c3 100644
--- a/pc/audio_rtp_receiver.h
+++ b/pc/audio_rtp_receiver.h
@@ -117,7 +117,7 @@
std::vector<RtpSource> GetSources() const override;
int AttachmentId() const override { return attachment_id_; }
- void SetDepacketizerToDecoderFrameTransformer(
+ void SetFrameTransformer(
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) override;
private:
diff --git a/pc/rtp_receiver_proxy.h b/pc/rtp_receiver_proxy.h
index d4114e0..db677d8 100644
--- a/pc/rtp_receiver_proxy.h
+++ b/pc/rtp_receiver_proxy.h
@@ -45,7 +45,7 @@
PROXY_SECONDARY_CONSTMETHOD0(rtc::scoped_refptr<FrameDecryptorInterface>,
GetFrameDecryptor)
PROXY_SECONDARY_METHOD1(void,
- SetDepacketizerToDecoderFrameTransformer,
+ SetFrameTransformer,
rtc::scoped_refptr<FrameTransformerInterface>)
END_PROXY_MAP(RtpReceiver)
diff --git a/pc/rtp_sender.cc b/pc/rtp_sender.cc
index be09757..60b8813 100644
--- a/pc/rtp_sender.cc
+++ b/pc/rtp_sender.cc
@@ -506,7 +506,7 @@
SetFrameEncryptor(frame_encryptor_);
}
if (frame_transformer_) {
- SetEncoderToPacketizerFrameTransformer(frame_transformer_);
+ SetFrameTransformer(frame_transformer_);
}
if (encoder_selector_) {
SetEncoderSelectorOnChannel();
@@ -580,7 +580,7 @@
return result;
}
-void RtpSenderBase::SetEncoderToPacketizerFrameTransformer(
+void RtpSenderBase::SetFrameTransformer(
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) {
RTC_DCHECK_RUN_ON(signaling_thread_);
frame_transformer_ = std::move(frame_transformer);
diff --git a/pc/rtp_sender.h b/pc/rtp_sender.h
index 90d33aa..bd2cf9d 100644
--- a/pc/rtp_sender.h
+++ b/pc/rtp_sender.h
@@ -206,7 +206,7 @@
// If the specified list is empty, this is a no-op.
RTCError DisableEncodingLayers(const std::vector<std::string>& rid) override;
- void SetEncoderToPacketizerFrameTransformer(
+ void SetFrameTransformer(
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) override;
void SetEncoderSelector(
diff --git a/pc/rtp_sender_proxy.h b/pc/rtp_sender_proxy.h
index 39862eb..8ed32f6 100644
--- a/pc/rtp_sender_proxy.h
+++ b/pc/rtp_sender_proxy.h
@@ -47,7 +47,7 @@
GetFrameEncryptor)
PROXY_METHOD1(void, SetStreams, const std::vector<std::string>&)
PROXY_METHOD1(void,
- SetEncoderToPacketizerFrameTransformer,
+ SetFrameTransformer,
rtc::scoped_refptr<FrameTransformerInterface>)
PROXY_METHOD1(void,
SetEncoderSelector,
diff --git a/pc/test/mock_rtp_sender_internal.h b/pc/test/mock_rtp_sender_internal.h
index 9a01aec..bb7776b 100644
--- a/pc/test/mock_rtp_sender_internal.h
+++ b/pc/test/mock_rtp_sender_internal.h
@@ -85,7 +85,7 @@
(),
(const, override));
MOCK_METHOD(void,
- SetEncoderToPacketizerFrameTransformer,
+ SetFrameTransformer,
(rtc::scoped_refptr<FrameTransformerInterface>),
(override));
MOCK_METHOD(void,
diff --git a/pc/video_rtp_receiver.cc b/pc/video_rtp_receiver.cc
index 4432982..6694d3e 100644
--- a/pc/video_rtp_receiver.cc
+++ b/pc/video_rtp_receiver.cc
@@ -98,7 +98,7 @@
return frame_decryptor_;
}
-void VideoRtpReceiver::SetDepacketizerToDecoderFrameTransformer(
+void VideoRtpReceiver::SetFrameTransformer(
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) {
RTC_DCHECK_RUN_ON(worker_thread_);
frame_transformer_ = std::move(frame_transformer);
diff --git a/pc/video_rtp_receiver.h b/pc/video_rtp_receiver.h
index ef88016..dfa491c 100644
--- a/pc/video_rtp_receiver.h
+++ b/pc/video_rtp_receiver.h
@@ -82,7 +82,7 @@
rtc::scoped_refptr<FrameDecryptorInterface> GetFrameDecryptor()
const override;
- void SetDepacketizerToDecoderFrameTransformer(
+ void SetFrameTransformer(
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) override;
// RtpReceiverInternal implementation.