diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /third_party/libwebrtc/audio/channel_receive_frame_transformer_delegate.cc | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/audio/channel_receive_frame_transformer_delegate.cc')
-rw-r--r-- | third_party/libwebrtc/audio/channel_receive_frame_transformer_delegate.cc | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/third_party/libwebrtc/audio/channel_receive_frame_transformer_delegate.cc b/third_party/libwebrtc/audio/channel_receive_frame_transformer_delegate.cc new file mode 100644 index 0000000000..e8ba6ded47 --- /dev/null +++ b/third_party/libwebrtc/audio/channel_receive_frame_transformer_delegate.cc @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "audio/channel_receive_frame_transformer_delegate.h" + +#include <utility> + +#include "rtc_base/buffer.h" + +namespace webrtc { +namespace { + +class TransformableIncomingAudioFrame + : public TransformableAudioFrameInterface { + public: + TransformableIncomingAudioFrame(rtc::ArrayView<const uint8_t> payload, + const RTPHeader& header, + uint32_t ssrc) + : payload_(payload.data(), payload.size()), + header_(header), + ssrc_(ssrc) {} + ~TransformableIncomingAudioFrame() override = default; + rtc::ArrayView<const uint8_t> GetData() const override { return payload_; } + + void SetData(rtc::ArrayView<const uint8_t> data) override { + payload_.SetData(data.data(), data.size()); + } + + uint8_t GetPayloadType() const override { return header_.payloadType; } + uint32_t GetSsrc() const override { return ssrc_; } + uint32_t GetTimestamp() const override { return header_.timestamp; } + const RTPHeader& GetHeader() const override { return header_; } + rtc::ArrayView<const uint32_t> GetContributingSources() const override { + return rtc::ArrayView<const uint32_t>(header_.arrOfCSRCs, header_.numCSRCs); + } + Direction GetDirection() const override { return Direction::kReceiver; } + + private: + rtc::Buffer payload_; + RTPHeader header_; + uint32_t ssrc_; +}; +} // namespace + +ChannelReceiveFrameTransformerDelegate::ChannelReceiveFrameTransformerDelegate( + ReceiveFrameCallback receive_frame_callback, + rtc::scoped_refptr<FrameTransformerInterface> frame_transformer, + TaskQueueBase* channel_receive_thread) + : receive_frame_callback_(receive_frame_callback), + frame_transformer_(std::move(frame_transformer)), + channel_receive_thread_(channel_receive_thread) {} + +void ChannelReceiveFrameTransformerDelegate::Init() { + RTC_DCHECK_RUN_ON(&sequence_checker_); + frame_transformer_->RegisterTransformedFrameCallback( + rtc::scoped_refptr<TransformedFrameCallback>(this)); +} + +void ChannelReceiveFrameTransformerDelegate::Reset() { + RTC_DCHECK_RUN_ON(&sequence_checker_); + frame_transformer_->UnregisterTransformedFrameCallback(); + frame_transformer_ = nullptr; + receive_frame_callback_ = ReceiveFrameCallback(); +} + +void ChannelReceiveFrameTransformerDelegate::Transform( + rtc::ArrayView<const uint8_t> packet, + const RTPHeader& header, + uint32_t ssrc) { + RTC_DCHECK_RUN_ON(&sequence_checker_); + frame_transformer_->Transform( + std::make_unique<TransformableIncomingAudioFrame>(packet, header, ssrc)); +} + +void ChannelReceiveFrameTransformerDelegate::OnTransformedFrame( + std::unique_ptr<TransformableFrameInterface> frame) { + rtc::scoped_refptr<ChannelReceiveFrameTransformerDelegate> delegate(this); + channel_receive_thread_->PostTask( + [delegate = std::move(delegate), frame = std::move(frame)]() mutable { + delegate->ReceiveFrame(std::move(frame)); + }); +} + +void ChannelReceiveFrameTransformerDelegate::ReceiveFrame( + std::unique_ptr<TransformableFrameInterface> frame) const { + RTC_DCHECK_RUN_ON(&sequence_checker_); + if (!receive_frame_callback_) + return; + RTC_CHECK_EQ(frame->GetDirection(), + TransformableFrameInterface::Direction::kReceiver); + auto* transformed_frame = + static_cast<TransformableIncomingAudioFrame*>(frame.get()); + receive_frame_callback_(transformed_frame->GetData(), + transformed_frame->GetHeader()); +} +} // namespace webrtc |