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 VIDEO_RTP_VIDEO_STREAM_RECEIVER_FRAME_TRANSFORMER_DELEGATE_H_
12 #define VIDEO_RTP_VIDEO_STREAM_RECEIVER_FRAME_TRANSFORMER_DELEGATE_H_
13 
14 #include <memory>
15 
16 #include "api/frame_transformer_interface.h"
17 #include "modules/video_coding/frame_object.h"
18 #include "rtc_base/synchronization/sequence_checker.h"
19 #include "rtc_base/thread.h"
20 
21 namespace webrtc {
22 
23 // Called back by RtpVideoStreamReceiverFrameTransformerDelegate on the network
24 // thread after transformation.
25 class RtpVideoFrameReceiver {
26  public:
27   virtual void ManageFrame(
28       std::unique_ptr<video_coding::RtpFrameObject> frame) = 0;
29 
30  protected:
31   virtual ~RtpVideoFrameReceiver() = default;
32 };
33 
34 // Delegates calls to FrameTransformerInterface to transform frames, and to
35 // RtpVideoStreamReceiver to manage transformed frames on the |network_thread_|.
36 class RtpVideoStreamReceiverFrameTransformerDelegate
37     : public TransformedFrameCallback {
38  public:
39   RtpVideoStreamReceiverFrameTransformerDelegate(
40       RtpVideoFrameReceiver* receiver,
41       rtc::scoped_refptr<FrameTransformerInterface> frame_transformer,
42       rtc::Thread* network_thread,
43       uint32_t ssrc);
44 
45   void Init();
46   void Reset();
47 
48   // Delegates the call to FrameTransformerInterface::TransformFrame.
49   void TransformFrame(std::unique_ptr<video_coding::RtpFrameObject> frame);
50 
51   // Implements TransformedFrameCallback. Can be called on any thread. Posts
52   // the transformed frame to be managed on the |network_thread_|.
53   void OnTransformedFrame(
54       std::unique_ptr<TransformableFrameInterface> frame) override;
55 
56   // Delegates the call to RtpVideoFrameReceiver::ManageFrame on the
57   // |network_thread_|.
58   void ManageFrame(std::unique_ptr<TransformableFrameInterface> frame);
59 
60  protected:
61   ~RtpVideoStreamReceiverFrameTransformerDelegate() override = default;
62 
63  private:
64   SequenceChecker network_sequence_checker_;
65   RtpVideoFrameReceiver* receiver_ RTC_GUARDED_BY(network_sequence_checker_);
66   rtc::scoped_refptr<FrameTransformerInterface> frame_transformer_
67       RTC_GUARDED_BY(network_sequence_checker_);
68   rtc::Thread* const network_thread_;
69   const uint32_t ssrc_;
70 };
71 
72 }  // namespace webrtc
73 
74 #endif  // VIDEO_RTP_VIDEO_STREAM_RECEIVER_FRAME_TRANSFORMER_DELEGATE_H_
75