blob: de2c612ac0912508717b3ac472a4d77e29605869 [file] [log] [blame]
Marina Cioceae3e07bf2020-02-27 15:28:511/*
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 Cioceacdc89b42020-05-14 18:01:0219#include "api/video/video_frame_metadata.h"
Marina Cioceae3e07bf2020-02-27 15:28:5120#include "rtc_base/ref_count.h"
21
22namespace webrtc {
23
Marina Cioceac24b6b72020-03-30 12:51:1024// Owns the frame payload data.
25class 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 Titov0e61fdd2021-07-25 19:50:1433 // Copies `data` into the owned frame payload data.
Marina Cioceac24b6b72020-03-30 12:51:1034 virtual void SetData(rtc::ArrayView<const uint8_t> data) = 0;
35
Olga Sharonova92e9ff62021-09-02 07:58:2136 virtual uint8_t GetPayloadType() const = 0;
Marina Cioceac24b6b72020-03-30 12:51:1037 virtual uint32_t GetSsrc() const = 0;
Philipp Hancke2ace42f2021-08-24 08:40:1238 virtual uint32_t GetTimestamp() const = 0;
Tony Herre8fb41a32021-09-24 12:05:2039
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 Cioceac24b6b72020-03-30 12:51:1049};
50
51class 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 Cioceacdc89b42020-05-14 18:01:0263
Marina Ciocea8de900c2020-05-18 14:04:4264 virtual const VideoFrameMetadata& GetMetadata() const = 0;
Marina Cioceac24b6b72020-03-30 12:51:1065};
66
Marina Ciocea48623202020-04-01 08:19:4467// Extends the TransformableFrameInterface to expose audio-specific information.
68class 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 Cioceae3e07bf2020-02-27 15:28:5178// Objects implement this interface to be notified with the transformed frame.
79class TransformedFrameCallback : public rtc::RefCountInterface {
80 public:
81 virtual void OnTransformedFrame(
Marina Ciocea81be4212020-05-05 14:03:5482 std::unique_ptr<TransformableFrameInterface> frame) = 0;
Marina Cioceae3e07bf2020-02-27 15:28:5183
84 protected:
85 ~TransformedFrameCallback() override = default;
86};
87
Marina Cioceac24b6b72020-03-30 12:51:1088// Transforms encoded frames. The transformed frame is sent in a callback using
89// the TransformedFrameCallback interface (see above).
Marina Cioceae3e07bf2020-02-27 15:28:5190class FrameTransformerInterface : public rtc::RefCountInterface {
91 public:
Artem Titov0e61fdd2021-07-25 19:50:1492 // Transforms `frame` using the implementing class' processing logic.
Marina Cioceac24b6b72020-03-30 12:51:1093 virtual void Transform(
Marina Ciocea81be4212020-05-05 14:03:5494 std::unique_ptr<TransformableFrameInterface> transformable_frame) = 0;
Marina Cioceae3e07bf2020-02-27 15:28:5195
96 virtual void RegisterTransformedFrameCallback(
Marina Cioceafdabfbc2020-04-10 16:40:1197 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 Cioceae3e07bf2020-02-27 15:28:51103
104 protected:
105 ~FrameTransformerInterface() override = default;
106};
107
108} // namespace webrtc
109
110#endif // API_FRAME_TRANSFORMER_INTERFACE_H_