blob: 7653bee3fbec853751c859ae27e9067d4d86978d [file] [log] [blame]
Marina Cioceae3e07bf2020-02-27 16:28:51 +01001/*
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 20:01:02 +020019#include "api/video/video_frame_metadata.h"
Marina Cioceae3e07bf2020-02-27 16:28:51 +010020#include "rtc_base/ref_count.h"
21
22namespace webrtc {
23
Marina Cioceac24b6b72020-03-30 14:51:10 +020024// 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 21:50:14 +020033 // Copies `data` into the owned frame payload data.
Marina Cioceac24b6b72020-03-30 14:51:10 +020034 virtual void SetData(rtc::ArrayView<const uint8_t> data) = 0;
35
Olga Sharonova92e9ff62021-09-02 07:58:21 +000036 virtual uint8_t GetPayloadType() const = 0;
Marina Cioceac24b6b72020-03-30 14:51:10 +020037 virtual uint32_t GetSsrc() const = 0;
Philipp Hancke2ace42f2021-08-24 10:40:12 +020038 virtual uint32_t GetTimestamp() const = 0;
Marina Cioceac24b6b72020-03-30 14:51:10 +020039};
40
41class 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 Cioceacdc89b42020-05-14 20:01:02 +020053
Marina Ciocea8de900c2020-05-18 14:04:42 +000054 virtual const VideoFrameMetadata& GetMetadata() const = 0;
Marina Cioceac24b6b72020-03-30 14:51:10 +020055};
56
Marina Ciocea48623202020-04-01 10:19:44 +020057// Extends the TransformableFrameInterface to expose audio-specific information.
58class 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 Cioceae3e07bf2020-02-27 16:28:51 +010068// Objects implement this interface to be notified with the transformed frame.
69class TransformedFrameCallback : public rtc::RefCountInterface {
70 public:
71 virtual void OnTransformedFrame(
Marina Ciocea81be4212020-05-05 16:03:54 +020072 std::unique_ptr<TransformableFrameInterface> frame) = 0;
Marina Cioceae3e07bf2020-02-27 16:28:51 +010073
74 protected:
75 ~TransformedFrameCallback() override = default;
76};
77
Marina Cioceac24b6b72020-03-30 14:51:10 +020078// Transforms encoded frames. The transformed frame is sent in a callback using
79// the TransformedFrameCallback interface (see above).
Marina Cioceae3e07bf2020-02-27 16:28:51 +010080class FrameTransformerInterface : public rtc::RefCountInterface {
81 public:
Artem Titov0e61fdd2021-07-25 21:50:14 +020082 // Transforms `frame` using the implementing class' processing logic.
Marina Cioceac24b6b72020-03-30 14:51:10 +020083 virtual void Transform(
Marina Ciocea81be4212020-05-05 16:03:54 +020084 std::unique_ptr<TransformableFrameInterface> transformable_frame) = 0;
Marina Cioceae3e07bf2020-02-27 16:28:51 +010085
86 virtual void RegisterTransformedFrameCallback(
Marina Cioceafdabfbc2020-04-10 18:40:11 +020087 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 Cioceae3e07bf2020-02-27 16:28:51 +010093
94 protected:
95 ~FrameTransformerInterface() override = default;
96};
97
98} // namespace webrtc
99
100#endif // API_FRAME_TRANSFORMER_INTERFACE_H_