blob: 062b31d3e03112ac070e9e3d2c2210ab0367fc4e [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"
19#include "rtc_base/ref_count.h"
20
21namespace webrtc {
22
Marina Cioceac24b6b72020-03-30 14:51:10 +020023// Owns the frame payload data.
24class TransformableFrameInterface {
25 public:
26 virtual ~TransformableFrameInterface() = default;
27
28 // Returns the frame payload data. The data is valid until the next non-const
29 // method call.
30 virtual rtc::ArrayView<const uint8_t> GetData() const = 0;
31
32 // Copies |data| into the owned frame payload data.
33 virtual void SetData(rtc::ArrayView<const uint8_t> data) = 0;
34
35 virtual uint32_t GetTimestamp() const = 0;
36 virtual uint32_t GetSsrc() const = 0;
37};
38
39class TransformableVideoFrameInterface : public TransformableFrameInterface {
40 public:
41 virtual ~TransformableVideoFrameInterface() = default;
42 virtual bool IsKeyFrame() const = 0;
43
44 // Returns data needed in the frame transformation logic; for example,
45 // when the transformation applied to the frame is encryption/decryption, the
46 // additional data holds the serialized generic frame descriptor extension
47 // calculated in webrtc::RtpDescriptorAuthentication.
48 // TODO(bugs.webrtc.org/11380) remove from interface once
49 // webrtc::RtpDescriptorAuthentication is exposed in api/.
50 virtual std::vector<uint8_t> GetAdditionalData() const = 0;
51};
52
Marina Ciocea48623202020-04-01 10:19:44 +020053// Extends the TransformableFrameInterface to expose audio-specific information.
54class TransformableAudioFrameInterface : public TransformableFrameInterface {
55 public:
56 virtual ~TransformableAudioFrameInterface() = default;
57
58 // Exposes the frame header, enabling the interface clients to use the
59 // information in the header as needed, for example to compile the list of
60 // csrcs.
61 virtual const RTPHeader& GetHeader() const = 0;
62};
63
Marina Cioceae3e07bf2020-02-27 16:28:51 +010064// Objects implement this interface to be notified with the transformed frame.
65class TransformedFrameCallback : public rtc::RefCountInterface {
66 public:
Marina Cioceac24b6b72020-03-30 14:51:10 +020067 // TODO(bugs.webrtc.org/11380) remove after updating downstream dependencies
68 // to use new OnTransformedFrame signature.
Marina Cioceae3e07bf2020-02-27 16:28:51 +010069 virtual void OnTransformedFrame(
Marina Cioceac24b6b72020-03-30 14:51:10 +020070 std::unique_ptr<video_coding::EncodedFrame> transformed_frame) {}
71 // TODO(bugs.webrtc.org/11380) make pure virtual after updating usage
72 // downstream.
73 virtual void OnTransformedFrame(
74 std::unique_ptr<TransformableFrameInterface> transformed_frame) {}
Marina Cioceae3e07bf2020-02-27 16:28:51 +010075
76 protected:
77 ~TransformedFrameCallback() override = default;
78};
79
Marina Cioceac24b6b72020-03-30 14:51:10 +020080// Transforms encoded frames. The transformed frame is sent in a callback using
81// the TransformedFrameCallback interface (see above).
Marina Cioceae3e07bf2020-02-27 16:28:51 +010082class FrameTransformerInterface : public rtc::RefCountInterface {
83 public:
84 // Transforms |frame| using the implementing class' processing logic.
85 // |additional_data| holds data that is needed in the frame transformation
86 // logic, but is not included in |frame|; for example, when the transform
87 // function is used for encrypting/decrypting the frame, the additional data
88 // holds the serialized generic frame descriptor extension calculated in
89 // webrtc::RtpDescriptorAuthentication, needed in the encryption/decryption
90 // algorithms.
Marina Cioceac24b6b72020-03-30 14:51:10 +020091 // TODO(bugs.webrtc.org/11380) remove after updating downstream dependencies
92 // to use new OnTransformedFrame() signature.
Marina Cioceae3e07bf2020-02-27 16:28:51 +010093 virtual void TransformFrame(std::unique_ptr<video_coding::EncodedFrame> frame,
94 std::vector<uint8_t> additional_data,
Marina Cioceac24b6b72020-03-30 14:51:10 +020095 uint32_t ssrc) {}
96
97 // Transforms |frame| using the implementing class' processing logic.
98 // TODO(bugs.webrtc.org/11380) make pure virtual after updating usage
99 // downstream.
100 virtual void Transform(
101 std::unique_ptr<TransformableFrameInterface> transformable_frame) {}
Marina Cioceae3e07bf2020-02-27 16:28:51 +0100102
103 virtual void RegisterTransformedFrameCallback(
Marina Cioceafdabfbc2020-04-10 18:40:11 +0200104 rtc::scoped_refptr<TransformedFrameCallback>) {}
105 virtual void RegisterTransformedFrameSinkCallback(
106 rtc::scoped_refptr<TransformedFrameCallback>,
107 uint32_t ssrc) {}
108 virtual void UnregisterTransformedFrameCallback() {}
109 virtual void UnregisterTransformedFrameSinkCallback(uint32_t ssrc) {}
Marina Cioceae3e07bf2020-02-27 16:28:51 +0100110
111 protected:
112 ~FrameTransformerInterface() override = default;
113};
114
115} // namespace webrtc
116
117#endif // API_FRAME_TRANSFORMER_INTERFACE_H_