blob: 0af748e37f1a2fe917794c5c210c1d580ac5e36b [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
26// |receive_frame_callback_| on the |channel_receive_thread_|.
27class 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,
35 rtc::Thread* channel_receive_thread);
36
37 // Registers |this| as callback for |frame_transformer_|, to get the
38 // transformed frames.
39 void Init();
40
41 // Unregisters and releases the |frame_transformer_| reference, and resets
42 // |receive_frame_callback_| on |channel_receive_thread_|. Called from
43 // 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
Marina Ciocea48623202020-04-01 08:19:4458 // |channel_receive_thread_|, by calling |receive_frame_callback_|.
59 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_);
70 rtc::Thread* channel_receive_thread_;
71};
72
73} // namespace webrtc
74#endif // AUDIO_CHANNEL_RECEIVE_FRAME_TRANSFORMER_DELEGATE_H_