blob: 615c97466e220648a0bfdd07289858bb64203819 [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 Cioceae3e07bf2020-02-27 16:28:51 +010053// Objects implement this interface to be notified with the transformed frame.
54class TransformedFrameCallback : public rtc::RefCountInterface {
55 public:
Marina Cioceac24b6b72020-03-30 14:51:10 +020056 // TODO(bugs.webrtc.org/11380) remove after updating downstream dependencies
57 // to use new OnTransformedFrame signature.
Marina Cioceae3e07bf2020-02-27 16:28:51 +010058 virtual void OnTransformedFrame(
Marina Cioceac24b6b72020-03-30 14:51:10 +020059 std::unique_ptr<video_coding::EncodedFrame> transformed_frame) {}
60 // TODO(bugs.webrtc.org/11380) make pure virtual after updating usage
61 // downstream.
62 virtual void OnTransformedFrame(
63 std::unique_ptr<TransformableFrameInterface> transformed_frame) {}
Marina Cioceae3e07bf2020-02-27 16:28:51 +010064
65 protected:
66 ~TransformedFrameCallback() override = default;
67};
68
Marina Cioceac24b6b72020-03-30 14:51:10 +020069// Transforms encoded frames. The transformed frame is sent in a callback using
70// the TransformedFrameCallback interface (see above).
Marina Cioceae3e07bf2020-02-27 16:28:51 +010071class FrameTransformerInterface : public rtc::RefCountInterface {
72 public:
73 // Transforms |frame| using the implementing class' processing logic.
74 // |additional_data| holds data that is needed in the frame transformation
75 // logic, but is not included in |frame|; for example, when the transform
76 // function is used for encrypting/decrypting the frame, the additional data
77 // holds the serialized generic frame descriptor extension calculated in
78 // webrtc::RtpDescriptorAuthentication, needed in the encryption/decryption
79 // algorithms.
Marina Cioceac24b6b72020-03-30 14:51:10 +020080 // TODO(bugs.webrtc.org/11380) remove after updating downstream dependencies
81 // to use new OnTransformedFrame() signature.
Marina Cioceae3e07bf2020-02-27 16:28:51 +010082 virtual void TransformFrame(std::unique_ptr<video_coding::EncodedFrame> frame,
83 std::vector<uint8_t> additional_data,
Marina Cioceac24b6b72020-03-30 14:51:10 +020084 uint32_t ssrc) {}
85
86 // Transforms |frame| using the implementing class' processing logic.
87 // TODO(bugs.webrtc.org/11380) make pure virtual after updating usage
88 // downstream.
89 virtual void Transform(
90 std::unique_ptr<TransformableFrameInterface> transformable_frame) {}
Marina Cioceae3e07bf2020-02-27 16:28:51 +010091
92 virtual void RegisterTransformedFrameCallback(
93 rtc::scoped_refptr<TransformedFrameCallback>) = 0;
94 virtual void UnregisterTransformedFrameCallback() = 0;
95
96 protected:
97 ~FrameTransformerInterface() override = default;
98};
99
100} // namespace webrtc
101
102#endif // API_FRAME_TRANSFORMER_INTERFACE_H_