channel_receive_frame_transformer_delegate.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #ifndef AUDIO_CHANNEL_RECEIVE_FRAME_TRANSFORMER_DELEGATE_H_
  11. #define AUDIO_CHANNEL_RECEIVE_FRAME_TRANSFORMER_DELEGATE_H_
  12. #include <memory>
  13. #include "api/frame_transformer_interface.h"
  14. #include "rtc_base/synchronization/sequence_checker.h"
  15. #include "rtc_base/system/no_unique_address.h"
  16. #include "rtc_base/task_queue.h"
  17. #include "rtc_base/thread.h"
  18. namespace webrtc {
  19. // Delegates calls to FrameTransformerInterface to transform frames, and to
  20. // ChannelReceive to receive the transformed frames using the
  21. // |receive_frame_callback_| on the |channel_receive_thread_|.
  22. class ChannelReceiveFrameTransformerDelegate : public TransformedFrameCallback {
  23. public:
  24. using ReceiveFrameCallback =
  25. std::function<void(rtc::ArrayView<const uint8_t> packet,
  26. const RTPHeader& header)>;
  27. ChannelReceiveFrameTransformerDelegate(
  28. ReceiveFrameCallback receive_frame_callback,
  29. rtc::scoped_refptr<FrameTransformerInterface> frame_transformer,
  30. rtc::Thread* channel_receive_thread);
  31. // Registers |this| as callback for |frame_transformer_|, to get the
  32. // transformed frames.
  33. void Init();
  34. // Unregisters and releases the |frame_transformer_| reference, and resets
  35. // |receive_frame_callback_| on |channel_receive_thread_|. Called from
  36. // ChannelReceive destructor to prevent running the callback on a dangling
  37. // channel.
  38. void Reset();
  39. // Delegates the call to FrameTransformerInterface::Transform, to transform
  40. // the frame asynchronously.
  41. void Transform(rtc::ArrayView<const uint8_t> packet,
  42. const RTPHeader& header,
  43. uint32_t ssrc);
  44. // Implements TransformedFrameCallback. Can be called on any thread.
  45. void OnTransformedFrame(
  46. std::unique_ptr<TransformableFrameInterface> frame) override;
  47. // Delegates the call to ChannelReceive::OnReceivedPayloadData on the
  48. // |channel_receive_thread_|, by calling |receive_frame_callback_|.
  49. void ReceiveFrame(std::unique_ptr<TransformableFrameInterface> frame) const;
  50. protected:
  51. ~ChannelReceiveFrameTransformerDelegate() override = default;
  52. private:
  53. RTC_NO_UNIQUE_ADDRESS SequenceChecker sequence_checker_;
  54. ReceiveFrameCallback receive_frame_callback_
  55. RTC_GUARDED_BY(sequence_checker_);
  56. rtc::scoped_refptr<FrameTransformerInterface> frame_transformer_
  57. RTC_GUARDED_BY(sequence_checker_);
  58. rtc::Thread* channel_receive_thread_;
  59. };
  60. } // namespace webrtc
  61. #endif // AUDIO_CHANNEL_RECEIVE_FRAME_TRANSFORMER_DELEGATE_H_