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" |
Marina Ciocea | cdc89b4 | 2020-05-14 20:01:02 +0200 | [diff] [blame] | 19 | #include "api/video/video_frame_metadata.h" |
Marina Ciocea | e3e07bf | 2020-02-27 16:28:51 +0100 | [diff] [blame] | 20 | #include "rtc_base/ref_count.h" |
| 21 | |
| 22 | namespace webrtc { |
| 23 | |
Marina Ciocea | c24b6b7 | 2020-03-30 14:51:10 +0200 | [diff] [blame] | 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 | |
Artem Titov | 0e61fdd | 2021-07-25 21:50:14 +0200 | [diff] [blame] | 33 | // Copies `data` into the owned frame payload data. |
Marina Ciocea | c24b6b7 | 2020-03-30 14:51:10 +0200 | [diff] [blame] | 34 | virtual void SetData(rtc::ArrayView<const uint8_t> data) = 0; |
| 35 | |
Olga Sharonova | 92e9ff6 | 2021-09-02 07:58:21 +0000 | [diff] [blame] | 36 | virtual uint8_t GetPayloadType() const = 0; |
Marina Ciocea | c24b6b7 | 2020-03-30 14:51:10 +0200 | [diff] [blame] | 37 | virtual uint32_t GetSsrc() const = 0; |
Philipp Hancke | 2ace42f | 2021-08-24 10:40:12 +0200 | [diff] [blame] | 38 | virtual uint32_t GetTimestamp() const = 0; |
Marina Ciocea | c24b6b7 | 2020-03-30 14:51:10 +0200 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | class TransformableVideoFrameInterface : public TransformableFrameInterface { |
| 42 | public: |
| 43 | virtual ~TransformableVideoFrameInterface() = default; |
| 44 | virtual bool IsKeyFrame() const = 0; |
| 45 | |
| 46 | // Returns data needed in the frame transformation logic; for example, |
| 47 | // when the transformation applied to the frame is encryption/decryption, the |
| 48 | // additional data holds the serialized generic frame descriptor extension |
| 49 | // calculated in webrtc::RtpDescriptorAuthentication. |
| 50 | // TODO(bugs.webrtc.org/11380) remove from interface once |
| 51 | // webrtc::RtpDescriptorAuthentication is exposed in api/. |
| 52 | virtual std::vector<uint8_t> GetAdditionalData() const = 0; |
Marina Ciocea | cdc89b4 | 2020-05-14 20:01:02 +0200 | [diff] [blame] | 53 | |
Marina Ciocea | 8de900c | 2020-05-18 14:04:42 +0000 | [diff] [blame] | 54 | virtual const VideoFrameMetadata& GetMetadata() const = 0; |
Marina Ciocea | c24b6b7 | 2020-03-30 14:51:10 +0200 | [diff] [blame] | 55 | }; |
| 56 | |
Marina Ciocea | 4862320 | 2020-04-01 10:19:44 +0200 | [diff] [blame] | 57 | // Extends the TransformableFrameInterface to expose audio-specific information. |
| 58 | class TransformableAudioFrameInterface : public TransformableFrameInterface { |
| 59 | public: |
| 60 | virtual ~TransformableAudioFrameInterface() = default; |
| 61 | |
| 62 | // Exposes the frame header, enabling the interface clients to use the |
| 63 | // information in the header as needed, for example to compile the list of |
| 64 | // csrcs. |
| 65 | virtual const RTPHeader& GetHeader() const = 0; |
| 66 | }; |
| 67 | |
Marina Ciocea | e3e07bf | 2020-02-27 16:28:51 +0100 | [diff] [blame] | 68 | // Objects implement this interface to be notified with the transformed frame. |
| 69 | class TransformedFrameCallback : public rtc::RefCountInterface { |
| 70 | public: |
| 71 | virtual void OnTransformedFrame( |
Marina Ciocea | 81be421 | 2020-05-05 16:03:54 +0200 | [diff] [blame] | 72 | std::unique_ptr<TransformableFrameInterface> frame) = 0; |
Marina Ciocea | e3e07bf | 2020-02-27 16:28:51 +0100 | [diff] [blame] | 73 | |
| 74 | protected: |
| 75 | ~TransformedFrameCallback() override = default; |
| 76 | }; |
| 77 | |
Marina Ciocea | c24b6b7 | 2020-03-30 14:51:10 +0200 | [diff] [blame] | 78 | // Transforms encoded frames. The transformed frame is sent in a callback using |
| 79 | // the TransformedFrameCallback interface (see above). |
Marina Ciocea | e3e07bf | 2020-02-27 16:28:51 +0100 | [diff] [blame] | 80 | class FrameTransformerInterface : public rtc::RefCountInterface { |
| 81 | public: |
Artem Titov | 0e61fdd | 2021-07-25 21:50:14 +0200 | [diff] [blame] | 82 | // Transforms `frame` using the implementing class' processing logic. |
Marina Ciocea | c24b6b7 | 2020-03-30 14:51:10 +0200 | [diff] [blame] | 83 | virtual void Transform( |
Marina Ciocea | 81be421 | 2020-05-05 16:03:54 +0200 | [diff] [blame] | 84 | std::unique_ptr<TransformableFrameInterface> transformable_frame) = 0; |
Marina Ciocea | e3e07bf | 2020-02-27 16:28:51 +0100 | [diff] [blame] | 85 | |
| 86 | virtual void RegisterTransformedFrameCallback( |
Marina Ciocea | fdabfbc | 2020-04-10 18:40:11 +0200 | [diff] [blame] | 87 | rtc::scoped_refptr<TransformedFrameCallback>) {} |
| 88 | virtual void RegisterTransformedFrameSinkCallback( |
| 89 | rtc::scoped_refptr<TransformedFrameCallback>, |
| 90 | uint32_t ssrc) {} |
| 91 | virtual void UnregisterTransformedFrameCallback() {} |
| 92 | virtual void UnregisterTransformedFrameSinkCallback(uint32_t ssrc) {} |
Marina Ciocea | e3e07bf | 2020-02-27 16:28:51 +0100 | [diff] [blame] | 93 | |
| 94 | protected: |
| 95 | ~FrameTransformerInterface() override = default; |
| 96 | }; |
| 97 | |
| 98 | } // namespace webrtc |
| 99 | |
| 100 | #endif // API_FRAME_TRANSFORMER_INTERFACE_H_ |