xref: /aosp_15_r20/external/webrtc/api/frame_transformer_interface.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright 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 API_FRAME_TRANSFORMER_INTERFACE_H_
12 #define API_FRAME_TRANSFORMER_INTERFACE_H_
13 
14 #include <memory>
15 #include <vector>
16 
17 #include "api/scoped_refptr.h"
18 #include "api/video/encoded_frame.h"
19 #include "api/video/video_frame_metadata.h"
20 #include "rtc_base/ref_count.h"
21 
22 namespace webrtc {
23 
24 // Owns the frame payload data.
25 class TransformableFrameInterface {
26  public:
27   virtual ~TransformableFrameInterface() = default;
28 
29   // Returns the frame payload data. The data is valid until the next non-const
30   // method call.
31   virtual rtc::ArrayView<const uint8_t> GetData() const = 0;
32 
33   // Copies `data` into the owned frame payload data.
34   virtual void SetData(rtc::ArrayView<const uint8_t> data) = 0;
35 
36   virtual uint8_t GetPayloadType() const = 0;
37   virtual uint32_t GetSsrc() const = 0;
38   virtual uint32_t GetTimestamp() const = 0;
39 
40   enum class Direction {
41     kUnknown,
42     kReceiver,
43     kSender,
44   };
45   // TODO(crbug.com/1250638): Remove this distinction between receiver and
46   // sender frames to allow received frames to be directly re-transmitted on
47   // other PeerConnectionss.
GetDirection()48   virtual Direction GetDirection() const { return Direction::kUnknown; }
49 };
50 
51 class TransformableVideoFrameInterface : public TransformableFrameInterface {
52  public:
53   virtual ~TransformableVideoFrameInterface() = default;
54   virtual bool IsKeyFrame() const = 0;
55 
56   // Returns data needed in the frame transformation logic; for example,
57   // when the transformation applied to the frame is encryption/decryption, the
58   // additional data holds the serialized generic frame descriptor extension
59   // calculated in webrtc::RtpDescriptorAuthentication.
60   // TODO(bugs.webrtc.org/11380) remove from interface once
61   // webrtc::RtpDescriptorAuthentication is exposed in api/.
62   virtual std::vector<uint8_t> GetAdditionalData() const = 0;
63 
64   virtual const VideoFrameMetadata& GetMetadata() const = 0;
65 };
66 
67 // Extends the TransformableFrameInterface to expose audio-specific information.
68 class TransformableAudioFrameInterface : public TransformableFrameInterface {
69  public:
70   virtual ~TransformableAudioFrameInterface() = default;
71 
72   // Exposes the frame header, enabling the interface clients to use the
73   // information in the header as needed, for example to compile the list of
74   // csrcs.
75   virtual const RTPHeader& GetHeader() const = 0;
76 
77   virtual rtc::ArrayView<const uint32_t> GetContributingSources() const = 0;
78 };
79 
80 // Objects implement this interface to be notified with the transformed frame.
81 class TransformedFrameCallback : public rtc::RefCountInterface {
82  public:
83   virtual void OnTransformedFrame(
84       std::unique_ptr<TransformableFrameInterface> frame) = 0;
85 
86  protected:
87   ~TransformedFrameCallback() override = default;
88 };
89 
90 // Transforms encoded frames. The transformed frame is sent in a callback using
91 // the TransformedFrameCallback interface (see above).
92 class FrameTransformerInterface : public rtc::RefCountInterface {
93  public:
94   // Transforms `frame` using the implementing class' processing logic.
95   virtual void Transform(
96       std::unique_ptr<TransformableFrameInterface> transformable_frame) = 0;
97 
RegisterTransformedFrameCallback(rtc::scoped_refptr<TransformedFrameCallback>)98   virtual void RegisterTransformedFrameCallback(
99       rtc::scoped_refptr<TransformedFrameCallback>) {}
RegisterTransformedFrameSinkCallback(rtc::scoped_refptr<TransformedFrameCallback>,uint32_t ssrc)100   virtual void RegisterTransformedFrameSinkCallback(
101       rtc::scoped_refptr<TransformedFrameCallback>,
102       uint32_t ssrc) {}
UnregisterTransformedFrameCallback()103   virtual void UnregisterTransformedFrameCallback() {}
UnregisterTransformedFrameSinkCallback(uint32_t ssrc)104   virtual void UnregisterTransformedFrameSinkCallback(uint32_t ssrc) {}
105 
106  protected:
107   ~FrameTransformerInterface() override = default;
108 };
109 
110 }  // namespace webrtc
111 
112 #endif  // API_FRAME_TRANSFORMER_INTERFACE_H_
113