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: |
| 67 | virtual void OnTransformedFrame( |
Marina Ciocea | 81be421 | 2020-05-05 16:03:54 +0200 | [diff] [blame^] | 68 | std::unique_ptr<TransformableFrameInterface> frame) = 0; |
Marina Ciocea | e3e07bf | 2020-02-27 16:28:51 +0100 | [diff] [blame] | 69 | |
| 70 | protected: |
| 71 | ~TransformedFrameCallback() override = default; |
| 72 | }; |
| 73 | |
Marina Ciocea | c24b6b7 | 2020-03-30 14:51:10 +0200 | [diff] [blame] | 74 | // Transforms encoded frames. The transformed frame is sent in a callback using |
| 75 | // the TransformedFrameCallback interface (see above). |
Marina Ciocea | e3e07bf | 2020-02-27 16:28:51 +0100 | [diff] [blame] | 76 | class FrameTransformerInterface : public rtc::RefCountInterface { |
| 77 | public: |
| 78 | // Transforms |frame| using the implementing class' processing logic. |
Marina Ciocea | c24b6b7 | 2020-03-30 14:51:10 +0200 | [diff] [blame] | 79 | virtual void Transform( |
Marina Ciocea | 81be421 | 2020-05-05 16:03:54 +0200 | [diff] [blame^] | 80 | std::unique_ptr<TransformableFrameInterface> transformable_frame) = 0; |
Marina Ciocea | e3e07bf | 2020-02-27 16:28:51 +0100 | [diff] [blame] | 81 | |
| 82 | virtual void RegisterTransformedFrameCallback( |
Marina Ciocea | fdabfbc | 2020-04-10 18:40:11 +0200 | [diff] [blame] | 83 | rtc::scoped_refptr<TransformedFrameCallback>) {} |
| 84 | virtual void RegisterTransformedFrameSinkCallback( |
| 85 | rtc::scoped_refptr<TransformedFrameCallback>, |
| 86 | uint32_t ssrc) {} |
| 87 | virtual void UnregisterTransformedFrameCallback() {} |
| 88 | virtual void UnregisterTransformedFrameSinkCallback(uint32_t ssrc) {} |
Marina Ciocea | e3e07bf | 2020-02-27 16:28:51 +0100 | [diff] [blame] | 89 | |
| 90 | protected: |
| 91 | ~FrameTransformerInterface() override = default; |
| 92 | }; |
| 93 | |
| 94 | } // namespace webrtc |
| 95 | |
| 96 | #endif // API_FRAME_TRANSFORMER_INTERFACE_H_ |