Marina Ciocea | e3e07bf | 2020-02-27 16:28:51 +0100 | [diff] [blame] | 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 "rtc_base/ref_count.h" |
| 20 | |
| 21 | namespace webrtc { |
| 22 | |
Marina Ciocea | c24b6b7 | 2020-03-30 14:51:10 +0200 | [diff] [blame] | 23 | // Owns the frame payload data. |
| 24 | class TransformableFrameInterface { |
| 25 | public: |
| 26 | virtual ~TransformableFrameInterface() = default; |
| 27 | |
| 28 | // Returns the frame payload data. The data is valid until the next non-const |
| 29 | // method call. |
| 30 | virtual rtc::ArrayView<const uint8_t> GetData() const = 0; |
| 31 | |
| 32 | // Copies |data| into the owned frame payload data. |
| 33 | virtual void SetData(rtc::ArrayView<const uint8_t> data) = 0; |
| 34 | |
| 35 | virtual uint32_t GetTimestamp() const = 0; |
| 36 | virtual uint32_t GetSsrc() const = 0; |
| 37 | }; |
| 38 | |
| 39 | class TransformableVideoFrameInterface : public TransformableFrameInterface { |
| 40 | public: |
| 41 | virtual ~TransformableVideoFrameInterface() = default; |
| 42 | virtual bool IsKeyFrame() const = 0; |
| 43 | |
| 44 | // Returns data needed in the frame transformation logic; for example, |
| 45 | // when the transformation applied to the frame is encryption/decryption, the |
| 46 | // additional data holds the serialized generic frame descriptor extension |
| 47 | // calculated in webrtc::RtpDescriptorAuthentication. |
| 48 | // TODO(bugs.webrtc.org/11380) remove from interface once |
| 49 | // webrtc::RtpDescriptorAuthentication is exposed in api/. |
| 50 | virtual std::vector<uint8_t> GetAdditionalData() const = 0; |
| 51 | }; |
| 52 | |
Marina Ciocea | 4862320 | 2020-04-01 10:19:44 +0200 | [diff] [blame] | 53 | // Extends the TransformableFrameInterface to expose audio-specific information. |
| 54 | class TransformableAudioFrameInterface : public TransformableFrameInterface { |
| 55 | public: |
| 56 | virtual ~TransformableAudioFrameInterface() = default; |
| 57 | |
| 58 | // Exposes the frame header, enabling the interface clients to use the |
| 59 | // information in the header as needed, for example to compile the list of |
| 60 | // csrcs. |
| 61 | virtual const RTPHeader& GetHeader() const = 0; |
| 62 | }; |
| 63 | |
Marina Ciocea | e3e07bf | 2020-02-27 16:28:51 +0100 | [diff] [blame] | 64 | // Objects implement this interface to be notified with the transformed frame. |
| 65 | class TransformedFrameCallback : public rtc::RefCountInterface { |
| 66 | public: |
Marina Ciocea | c24b6b7 | 2020-03-30 14:51:10 +0200 | [diff] [blame] | 67 | // TODO(bugs.webrtc.org/11380) remove after updating downstream dependencies |
| 68 | // to use new OnTransformedFrame signature. |
Marina Ciocea | e3e07bf | 2020-02-27 16:28:51 +0100 | [diff] [blame] | 69 | virtual void OnTransformedFrame( |
Marina Ciocea | c24b6b7 | 2020-03-30 14:51:10 +0200 | [diff] [blame] | 70 | std::unique_ptr<video_coding::EncodedFrame> transformed_frame) {} |
| 71 | // TODO(bugs.webrtc.org/11380) make pure virtual after updating usage |
| 72 | // downstream. |
| 73 | virtual void OnTransformedFrame( |
| 74 | std::unique_ptr<TransformableFrameInterface> transformed_frame) {} |
Marina Ciocea | e3e07bf | 2020-02-27 16:28:51 +0100 | [diff] [blame] | 75 | |
| 76 | protected: |
| 77 | ~TransformedFrameCallback() override = default; |
| 78 | }; |
| 79 | |
Marina Ciocea | c24b6b7 | 2020-03-30 14:51:10 +0200 | [diff] [blame] | 80 | // Transforms encoded frames. The transformed frame is sent in a callback using |
| 81 | // the TransformedFrameCallback interface (see above). |
Marina Ciocea | e3e07bf | 2020-02-27 16:28:51 +0100 | [diff] [blame] | 82 | class FrameTransformerInterface : public rtc::RefCountInterface { |
| 83 | public: |
| 84 | // Transforms |frame| using the implementing class' processing logic. |
| 85 | // |additional_data| holds data that is needed in the frame transformation |
| 86 | // logic, but is not included in |frame|; for example, when the transform |
| 87 | // function is used for encrypting/decrypting the frame, the additional data |
| 88 | // holds the serialized generic frame descriptor extension calculated in |
| 89 | // webrtc::RtpDescriptorAuthentication, needed in the encryption/decryption |
| 90 | // algorithms. |
Marina Ciocea | c24b6b7 | 2020-03-30 14:51:10 +0200 | [diff] [blame] | 91 | // TODO(bugs.webrtc.org/11380) remove after updating downstream dependencies |
| 92 | // to use new OnTransformedFrame() signature. |
Marina Ciocea | e3e07bf | 2020-02-27 16:28:51 +0100 | [diff] [blame] | 93 | virtual void TransformFrame(std::unique_ptr<video_coding::EncodedFrame> frame, |
| 94 | std::vector<uint8_t> additional_data, |
Marina Ciocea | c24b6b7 | 2020-03-30 14:51:10 +0200 | [diff] [blame] | 95 | uint32_t ssrc) {} |
| 96 | |
| 97 | // Transforms |frame| using the implementing class' processing logic. |
| 98 | // TODO(bugs.webrtc.org/11380) make pure virtual after updating usage |
| 99 | // downstream. |
| 100 | virtual void Transform( |
| 101 | std::unique_ptr<TransformableFrameInterface> transformable_frame) {} |
Marina Ciocea | e3e07bf | 2020-02-27 16:28:51 +0100 | [diff] [blame] | 102 | |
| 103 | virtual void RegisterTransformedFrameCallback( |
Marina Ciocea | fdabfbc | 2020-04-10 18:40:11 +0200 | [diff] [blame^] | 104 | rtc::scoped_refptr<TransformedFrameCallback>) {} |
| 105 | virtual void RegisterTransformedFrameSinkCallback( |
| 106 | rtc::scoped_refptr<TransformedFrameCallback>, |
| 107 | uint32_t ssrc) {} |
| 108 | virtual void UnregisterTransformedFrameCallback() {} |
| 109 | virtual void UnregisterTransformedFrameSinkCallback(uint32_t ssrc) {} |
Marina Ciocea | e3e07bf | 2020-02-27 16:28:51 +0100 | [diff] [blame] | 110 | |
| 111 | protected: |
| 112 | ~FrameTransformerInterface() override = default; |
| 113 | }; |
| 114 | |
| 115 | } // namespace webrtc |
| 116 | |
| 117 | #endif // API_FRAME_TRANSFORMER_INTERFACE_H_ |