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> |
Philipp Hancke | 0bace22 | 2023-10-23 09:57:43 | [diff] [blame] | 15 | #include <string> |
Marina Ciocea | e3e07bf | 2020-02-27 15:28:51 | [diff] [blame] | 16 | |
Harald Alvestrand | e8a2b3c | 2023-10-31 13:30:30 | [diff] [blame] | 17 | #include "api/ref_count.h" |
Marina Ciocea | e3e07bf | 2020-02-27 15:28:51 | [diff] [blame] | 18 | #include "api/scoped_refptr.h" |
| 19 | #include "api/video/encoded_frame.h" |
Marina Ciocea | cdc89b4 | 2020-05-14 18:01:02 | [diff] [blame] | 20 | #include "api/video/video_frame_metadata.h" |
Marina Ciocea | e3e07bf | 2020-02-27 15:28:51 | [diff] [blame] | 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 | b4062e5 | 2023-06-29 09:02:22 | [diff] [blame] | 39 | virtual void SetRTPTimestamp(uint32_t timestamp) = 0; |
| 40 | |
Palak Agarwal | a09f21b | 2023-02-22 13:46:23 | [diff] [blame] | 41 | // TODO(https://bugs.webrtc.org/14878): Change this to pure virtual after it |
| 42 | // is implemented everywhere. |
| 43 | virtual absl::optional<Timestamp> GetCaptureTimeIdentifier() const { |
| 44 | return absl::nullopt; |
| 45 | } |
Tony Herre | 8fb41a3 | 2021-09-24 12:05:20 | [diff] [blame] | 46 | |
| 47 | enum class Direction { |
| 48 | kUnknown, |
| 49 | kReceiver, |
| 50 | kSender, |
| 51 | }; |
| 52 | // TODO(crbug.com/1250638): Remove this distinction between receiver and |
| 53 | // sender frames to allow received frames to be directly re-transmitted on |
| 54 | // other PeerConnectionss. |
| 55 | virtual Direction GetDirection() const { return Direction::kUnknown; } |
Philipp Hancke | 3e3881a | 2023-11-06 10:28:30 | [diff] [blame] | 56 | virtual std::string GetMimeType() const = 0; |
Marina Ciocea | c24b6b7 | 2020-03-30 12:51:10 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | class TransformableVideoFrameInterface : public TransformableFrameInterface { |
| 60 | public: |
| 61 | virtual ~TransformableVideoFrameInterface() = default; |
| 62 | virtual bool IsKeyFrame() const = 0; |
| 63 | |
Tony Herre | 6d262c5 | 2023-02-24 11:20:28 | [diff] [blame] | 64 | virtual VideoFrameMetadata Metadata() const = 0; |
| 65 | |
Tony Herre | c381c33 | 2023-04-13 07:37:55 | [diff] [blame] | 66 | virtual void SetMetadata(const VideoFrameMetadata&) = 0; |
Marina Ciocea | c24b6b7 | 2020-03-30 12:51:10 | [diff] [blame] | 67 | }; |
| 68 | |
Marina Ciocea | 4862320 | 2020-04-01 08:19:44 | [diff] [blame] | 69 | // Extends the TransformableFrameInterface to expose audio-specific information. |
| 70 | class TransformableAudioFrameInterface : public TransformableFrameInterface { |
| 71 | public: |
| 72 | virtual ~TransformableAudioFrameInterface() = default; |
| 73 | |
Sergio Garcia Murillo | 15dfc5a | 2022-10-11 10:34:44 | [diff] [blame] | 74 | virtual rtc::ArrayView<const uint32_t> GetContributingSources() const = 0; |
Tony Herre | 097a4de | 2023-06-19 15:13:08 | [diff] [blame] | 75 | |
| 76 | // TODO(crbug.com/1453226): Change this to pure virtual after it |
| 77 | // is implemented everywhere. |
| 78 | virtual const absl::optional<uint16_t> SequenceNumber() const { |
| 79 | return absl::nullopt; |
| 80 | } |
Tony Herre | fc68f1f | 2023-06-22 13:32:24 | [diff] [blame] | 81 | |
Palak Agarwal | 0505115 | 2023-09-20 08:01:18 | [diff] [blame] | 82 | virtual absl::optional<uint64_t> AbsoluteCaptureTimestamp() const = 0; |
Tony Herre | fc68f1f | 2023-06-22 13:32:24 | [diff] [blame] | 83 | |
| 84 | enum class FrameType { kEmptyFrame, kAudioFrameSpeech, kAudioFrameCN }; |
| 85 | |
| 86 | // TODO(crbug.com/1456628): Change this to pure virtual after it |
| 87 | // is implemented everywhere. |
| 88 | virtual FrameType Type() const { return FrameType::kEmptyFrame; } |
Marina Ciocea | 4862320 | 2020-04-01 08:19:44 | [diff] [blame] | 89 | }; |
| 90 | |
Marina Ciocea | e3e07bf | 2020-02-27 15:28:51 | [diff] [blame] | 91 | // Objects implement this interface to be notified with the transformed frame. |
| 92 | class TransformedFrameCallback : public rtc::RefCountInterface { |
| 93 | public: |
| 94 | virtual void OnTransformedFrame( |
Marina Ciocea | 81be421 | 2020-05-05 14:03:54 | [diff] [blame] | 95 | std::unique_ptr<TransformableFrameInterface> frame) = 0; |
Marina Ciocea | e3e07bf | 2020-02-27 15:28:51 | [diff] [blame] | 96 | |
Tony Herre | 6e95605 | 2023-11-16 13:59:54 | [diff] [blame] | 97 | // Request to no longer be called on each frame, instead having frames be |
| 98 | // sent directly to OnTransformedFrame without additional work. |
| 99 | // TODO(crbug.com/1502781): Make pure virtual once all mocks have |
| 100 | // implementations. |
| 101 | virtual void StartShortCircuiting() {} |
| 102 | |
Marina Ciocea | e3e07bf | 2020-02-27 15:28:51 | [diff] [blame] | 103 | protected: |
| 104 | ~TransformedFrameCallback() override = default; |
| 105 | }; |
| 106 | |
Marina Ciocea | c24b6b7 | 2020-03-30 12:51:10 | [diff] [blame] | 107 | // Transforms encoded frames. The transformed frame is sent in a callback using |
| 108 | // the TransformedFrameCallback interface (see above). |
Marina Ciocea | e3e07bf | 2020-02-27 15:28:51 | [diff] [blame] | 109 | class FrameTransformerInterface : public rtc::RefCountInterface { |
| 110 | public: |
Artem Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 111 | // Transforms `frame` using the implementing class' processing logic. |
Marina Ciocea | c24b6b7 | 2020-03-30 12:51:10 | [diff] [blame] | 112 | virtual void Transform( |
Marina Ciocea | 81be421 | 2020-05-05 14:03:54 | [diff] [blame] | 113 | std::unique_ptr<TransformableFrameInterface> transformable_frame) = 0; |
Marina Ciocea | e3e07bf | 2020-02-27 15:28:51 | [diff] [blame] | 114 | |
| 115 | virtual void RegisterTransformedFrameCallback( |
Marina Ciocea | fdabfbc | 2020-04-10 16:40:11 | [diff] [blame] | 116 | rtc::scoped_refptr<TransformedFrameCallback>) {} |
| 117 | virtual void RegisterTransformedFrameSinkCallback( |
| 118 | rtc::scoped_refptr<TransformedFrameCallback>, |
| 119 | uint32_t ssrc) {} |
| 120 | virtual void UnregisterTransformedFrameCallback() {} |
| 121 | virtual void UnregisterTransformedFrameSinkCallback(uint32_t ssrc) {} |
Marina Ciocea | e3e07bf | 2020-02-27 15:28:51 | [diff] [blame] | 122 | |
| 123 | protected: |
| 124 | ~FrameTransformerInterface() override = default; |
| 125 | }; |
| 126 | |
| 127 | } // namespace webrtc |
| 128 | |
| 129 | #endif // API_FRAME_TRANSFORMER_INTERFACE_H_ |