1 /* 2 * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef AUDIO_CHANNEL_RECEIVE_FRAME_TRANSFORMER_DELEGATE_H_ 12 #define AUDIO_CHANNEL_RECEIVE_FRAME_TRANSFORMER_DELEGATE_H_ 13 14 #include <memory> 15 16 #include "api/frame_transformer_interface.h" 17 #include "rtc_base/synchronization/sequence_checker.h" 18 #include "rtc_base/task_queue.h" 19 #include "rtc_base/thread.h" 20 21 namespace webrtc { 22 23 // Delegates calls to FrameTransformerInterface to transform frames, and to 24 // ChannelReceive to receive the transformed frames using the 25 // |receive_frame_callback_| on the |channel_receive_thread_|. 26 class ChannelReceiveFrameTransformerDelegate : public TransformedFrameCallback { 27 public: 28 using ReceiveFrameCallback = 29 std::function<void(rtc::ArrayView<const uint8_t> packet, 30 const RTPHeader& header)>; 31 ChannelReceiveFrameTransformerDelegate( 32 ReceiveFrameCallback receive_frame_callback, 33 rtc::scoped_refptr<FrameTransformerInterface> frame_transformer, 34 rtc::Thread* channel_receive_thread); 35 36 // Registers |this| as callback for |frame_transformer_|, to get the 37 // transformed frames. 38 void Init(); 39 40 // Unregisters and releases the |frame_transformer_| reference, and resets 41 // |receive_frame_callback_| on |channel_receive_thread_|. Called from 42 // ChannelReceive destructor to prevent running the callback on a dangling 43 // channel. 44 void Reset(); 45 46 // Delegates the call to FrameTransformerInterface::Transform, to transform 47 // the frame asynchronously. 48 void Transform(rtc::ArrayView<const uint8_t> packet, 49 const RTPHeader& header, 50 uint32_t ssrc); 51 52 // Implements TransformedFrameCallback. Can be called on any thread. 53 void OnTransformedFrame( 54 std::unique_ptr<TransformableFrameInterface> frame) override; 55 56 // Delegates the call to ChannelReceive::OnReceivedPayloadData on the 57 // |channel_receive_thread_|, by calling |receive_frame_callback_|. 58 void ReceiveFrame(std::unique_ptr<TransformableFrameInterface> frame) const; 59 60 protected: 61 ~ChannelReceiveFrameTransformerDelegate() override = default; 62 63 private: 64 SequenceChecker sequence_checker_; 65 ReceiveFrameCallback receive_frame_callback_ 66 RTC_GUARDED_BY(sequence_checker_); 67 rtc::scoped_refptr<FrameTransformerInterface> frame_transformer_ 68 RTC_GUARDED_BY(sequence_checker_); 69 rtc::Thread* channel_receive_thread_; 70 }; 71 72 } // namespace webrtc 73 #endif // AUDIO_CHANNEL_RECEIVE_FRAME_TRANSFORMER_DELEGATE_H_ 74