Marina Ciocea | e3e07bf | 2020-02-27 15:28:51 | [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 18:01:02 | [diff] [blame] | 19 | #include "api/video/video_frame_metadata.h" |
Marina Ciocea | e3e07bf | 2020-02-27 15:28:51 | [diff] [blame] | 20 | #include "rtc_base/ref_count.h" |
| 21 | |
| 22 | namespace webrtc { |
| 23 | |
Marina Ciocea | c24b6b7 | 2020-03-30 12:51:10 | [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 19:50:14 | [diff] [blame] | 33 | // Copies `data` into the owned frame payload data. |
Marina Ciocea | c24b6b7 | 2020-03-30 12:51:10 | [diff] [blame] | 34 | virtual void SetData(rtc::ArrayView<const uint8_t> data) = 0; |
| 35 | |
Olga Sharonova | 92e9ff6 | 2021-09-02 07:58:21 | [diff] [blame] | 36 | virtual uint8_t GetPayloadType() const = 0; |
Marina Ciocea | c24b6b7 | 2020-03-30 12:51:10 | [diff] [blame] | 37 | virtual uint32_t GetSsrc() const = 0; |
Philipp Hancke | 2ace42f | 2021-08-24 08:40:12 | [diff] [blame] | 38 | virtual uint32_t GetTimestamp() const = 0; |
Tony Herre | 8fb41a3 | 2021-09-24 12:05:20 | [diff] [blame] | 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. |
| 48 | virtual Direction GetDirection() const { return Direction::kUnknown; } |
Marina Ciocea | c24b6b7 | 2020-03-30 12:51:10 | [diff] [blame] | 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; |
Marina Ciocea | cdc89b4 | 2020-05-14 18:01:02 | [diff] [blame] | 63 | |
Marina Ciocea | 8de900c | 2020-05-18 14:04:42 | [diff] [blame] | 64 | virtual const VideoFrameMetadata& GetMetadata() const = 0; |
Marina Ciocea | c24b6b7 | 2020-03-30 12:51:10 | [diff] [blame] | 65 | }; |
| 66 | |
Marina Ciocea | 4862320 | 2020-04-01 08:19:44 | [diff] [blame] | 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 | |
Marina Ciocea | e3e07bf | 2020-02-27 15:28:51 | [diff] [blame] | 78 | // Objects implement this interface to be notified with the transformed frame. |
| 79 | class TransformedFrameCallback : public rtc::RefCountInterface { |
| 80 | public: |
| 81 | virtual void OnTransformedFrame( |
Marina Ciocea | 81be421 | 2020-05-05 14:03:54 | [diff] [blame] | 82 | std::unique_ptr<TransformableFrameInterface> frame) = 0; |
Marina Ciocea | e3e07bf | 2020-02-27 15:28:51 | [diff] [blame] | 83 | |
| 84 | protected: |
| 85 | ~TransformedFrameCallback() override = default; |
| 86 | }; |
| 87 | |
Marina Ciocea | c24b6b7 | 2020-03-30 12:51:10 | [diff] [blame] | 88 | // Transforms encoded frames. The transformed frame is sent in a callback using |
| 89 | // the TransformedFrameCallback interface (see above). |
Marina Ciocea | e3e07bf | 2020-02-27 15:28:51 | [diff] [blame] | 90 | class FrameTransformerInterface : public rtc::RefCountInterface { |
| 91 | public: |
Artem Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 92 | // Transforms `frame` using the implementing class' processing logic. |
Marina Ciocea | c24b6b7 | 2020-03-30 12:51:10 | [diff] [blame] | 93 | virtual void Transform( |
Marina Ciocea | 81be421 | 2020-05-05 14:03:54 | [diff] [blame] | 94 | std::unique_ptr<TransformableFrameInterface> transformable_frame) = 0; |
Marina Ciocea | e3e07bf | 2020-02-27 15:28:51 | [diff] [blame] | 95 | |
| 96 | virtual void RegisterTransformedFrameCallback( |
Marina Ciocea | fdabfbc | 2020-04-10 16:40:11 | [diff] [blame] | 97 | rtc::scoped_refptr<TransformedFrameCallback>) {} |
| 98 | virtual void RegisterTransformedFrameSinkCallback( |
| 99 | rtc::scoped_refptr<TransformedFrameCallback>, |
| 100 | uint32_t ssrc) {} |
| 101 | virtual void UnregisterTransformedFrameCallback() {} |
| 102 | virtual void UnregisterTransformedFrameSinkCallback(uint32_t ssrc) {} |
Marina Ciocea | e3e07bf | 2020-02-27 15:28:51 | [diff] [blame] | 103 | |
| 104 | protected: |
| 105 | ~FrameTransformerInterface() override = default; |
| 106 | }; |
| 107 | |
| 108 | } // namespace webrtc |
| 109 | |
| 110 | #endif // API_FRAME_TRANSFORMER_INTERFACE_H_ |