blob: 04ad7c4695b905ac4255bf8c79b07e910eb1a654 [file] [log] [blame]
Marina Ciocea48623202020-04-01 08:19:441/*
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"
Artem Titovd15a5752021-02-10 13:31:2417#include "api/sequence_checker.h"
Mirko Bonadei20e4c802020-11-23 10:07:4218#include "rtc_base/system/no_unique_address.h"
Marina Ciocea48623202020-04-01 08:19:4419#include "rtc_base/task_queue.h"
20#include "rtc_base/thread.h"
21
22namespace webrtc {
23
24// Delegates calls to FrameTransformerInterface to transform frames, and to
25// ChannelReceive to receive the transformed frames using the
Artem Titovb0ea6372021-07-26 09:47:0726// `receive_frame_callback_` on the `channel_receive_thread_`.
Marina Ciocea48623202020-04-01 08:19:4427class ChannelReceiveFrameTransformerDelegate : public TransformedFrameCallback {
28 public:
29 using ReceiveFrameCallback =
30 std::function<void(rtc::ArrayView<const uint8_t> packet,
31 const RTPHeader& header)>;
32 ChannelReceiveFrameTransformerDelegate(
33 ReceiveFrameCallback receive_frame_callback,
34 rtc::scoped_refptr<FrameTransformerInterface> frame_transformer,
Tommie2e04642021-06-09 14:11:1135 TaskQueueBase* channel_receive_thread);
Marina Ciocea48623202020-04-01 08:19:4436
Artem Titovb0ea6372021-07-26 09:47:0737 // Registers `this` as callback for `frame_transformer_`, to get the
Marina Ciocea48623202020-04-01 08:19:4438 // transformed frames.
39 void Init();
40
Artem Titovb0ea6372021-07-26 09:47:0741 // Unregisters and releases the `frame_transformer_` reference, and resets
42 // `receive_frame_callback_` on `channel_receive_thread_`. Called from
Marina Ciocea48623202020-04-01 08:19:4443 // ChannelReceive destructor to prevent running the callback on a dangling
44 // channel.
45 void Reset();
46
47 // Delegates the call to FrameTransformerInterface::Transform, to transform
48 // the frame asynchronously.
49 void Transform(rtc::ArrayView<const uint8_t> packet,
50 const RTPHeader& header,
51 uint32_t ssrc);
52
53 // Implements TransformedFrameCallback. Can be called on any thread.
54 void OnTransformedFrame(
55 std::unique_ptr<TransformableFrameInterface> frame) override;
56
Marina Cioceafc23cc02020-04-02 10:10:0357 // Delegates the call to ChannelReceive::OnReceivedPayloadData on the
Artem Titovb0ea6372021-07-26 09:47:0758 // `channel_receive_thread_`, by calling `receive_frame_callback_`.
Marina Ciocea48623202020-04-01 08:19:4459 void ReceiveFrame(std::unique_ptr<TransformableFrameInterface> frame) const;
60
61 protected:
62 ~ChannelReceiveFrameTransformerDelegate() override = default;
63
64 private:
Mirko Bonadei20e4c802020-11-23 10:07:4265 RTC_NO_UNIQUE_ADDRESS SequenceChecker sequence_checker_;
Marina Ciocea48623202020-04-01 08:19:4466 ReceiveFrameCallback receive_frame_callback_
67 RTC_GUARDED_BY(sequence_checker_);
68 rtc::scoped_refptr<FrameTransformerInterface> frame_transformer_
69 RTC_GUARDED_BY(sequence_checker_);
Tommie2e04642021-06-09 14:11:1170 TaskQueueBase* const channel_receive_thread_;
Marina Ciocea48623202020-04-01 08:19:4471};
72
73} // namespace webrtc
74#endif // AUDIO_CHANNEL_RECEIVE_FRAME_TRANSFORMER_DELEGATE_H_