• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 MODULES_RTP_RTCP_SOURCE_RTP_SENDER_VIDEO_FRAME_TRANSFORMER_DELEGATE_H_
12 #define MODULES_RTP_RTCP_SOURCE_RTP_SENDER_VIDEO_FRAME_TRANSFORMER_DELEGATE_H_
13 
14 #include <memory>
15 
16 #include "api/frame_transformer_interface.h"
17 #include "api/scoped_refptr.h"
18 #include "api/task_queue/task_queue_base.h"
19 #include "rtc_base/synchronization/mutex.h"
20 
21 namespace webrtc {
22 
23 class RTPSenderVideo;
24 
25 // Delegates calls to FrameTransformerInterface to transform frames, and to
26 // RTPSenderVideo to send the transformed frames. Ensures thread-safe access to
27 // the sender.
28 class RTPSenderVideoFrameTransformerDelegate : public TransformedFrameCallback {
29  public:
30   RTPSenderVideoFrameTransformerDelegate(
31       RTPSenderVideo* sender,
32       rtc::scoped_refptr<FrameTransformerInterface> frame_transformer,
33       uint32_t ssrc,
34       TaskQueueBase* send_transport_queue);
35 
36   void Init();
37 
38   // Delegates the call to FrameTransformerInterface::TransformFrame.
39   bool TransformFrame(int payload_type,
40                       absl::optional<VideoCodecType> codec_type,
41                       uint32_t rtp_timestamp,
42                       const EncodedImage& encoded_image,
43                       RTPVideoHeader video_header,
44                       absl::optional<int64_t> expected_retransmission_time_ms);
45 
46   // Implements TransformedFrameCallback. Can be called on any thread. Posts
47   // the transformed frame to be sent on the |encoder_queue_|.
48   void OnTransformedFrame(
49       std::unique_ptr<TransformableFrameInterface> frame) override;
50 
51   // Delegates the call to RTPSendVideo::SendVideo on the |encoder_queue_|.
52   void SendVideo(std::unique_ptr<TransformableFrameInterface> frame) const;
53 
54   // Delegates the call to RTPSendVideo::SendVideo under |sender_lock_|.
55   void SetVideoStructureUnderLock(
56       const FrameDependencyStructure* video_structure);
57 
58   // Unregisters and releases the |frame_transformer_| reference, and resets
59   // |sender_| under lock. Called from RTPSenderVideo destructor to prevent the
60   // |sender_| to dangle.
61   void Reset();
62 
63  protected:
64   ~RTPSenderVideoFrameTransformerDelegate() override = default;
65 
66  private:
67   mutable Mutex sender_lock_;
68   RTPSenderVideo* sender_ RTC_GUARDED_BY(sender_lock_);
69   rtc::scoped_refptr<FrameTransformerInterface> frame_transformer_;
70   const uint32_t ssrc_;
71   TaskQueueBase* encoder_queue_ = nullptr;
72   TaskQueueBase* send_transport_queue_;
73 };
74 
75 }  // namespace webrtc
76 
77 #endif  // MODULES_RTP_RTCP_SOURCE_RTP_SENDER_VIDEO_FRAME_TRANSFORMER_DELEGATE_H_
78