blob: e712b3c190a33507a71d251ca30a59f635637bcd [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:
67 virtual void OnTransformedFrame(
Marina Ciocea81be4212020-05-05 16:03:54 +020068 std::unique_ptr<TransformableFrameInterface> frame) = 0;
Marina Cioceae3e07bf2020-02-27 16:28:51 +010069
70 protected:
71 ~TransformedFrameCallback() override = default;
72};
73
Marina Cioceac24b6b72020-03-30 14:51:10 +020074// Transforms encoded frames. The transformed frame is sent in a callback using
75// the TransformedFrameCallback interface (see above).
Marina Cioceae3e07bf2020-02-27 16:28:51 +010076class FrameTransformerInterface : public rtc::RefCountInterface {
77 public:
78 // Transforms |frame| using the implementing class' processing logic.
Marina Cioceac24b6b72020-03-30 14:51:10 +020079 virtual void Transform(
Marina Ciocea81be4212020-05-05 16:03:54 +020080 std::unique_ptr<TransformableFrameInterface> transformable_frame) = 0;
Marina Cioceae3e07bf2020-02-27 16:28:51 +010081
82 virtual void RegisterTransformedFrameCallback(
Marina Cioceafdabfbc2020-04-10 18:40:11 +020083 rtc::scoped_refptr<TransformedFrameCallback>) {}
84 virtual void RegisterTransformedFrameSinkCallback(
85 rtc::scoped_refptr<TransformedFrameCallback>,
86 uint32_t ssrc) {}
87 virtual void UnregisterTransformedFrameCallback() {}
88 virtual void UnregisterTransformedFrameSinkCallback(uint32_t ssrc) {}
Marina Cioceae3e07bf2020-02-27 16:28:51 +010089
90 protected:
91 ~FrameTransformerInterface() override = default;
92};
93
94} // namespace webrtc
95
96#endif // API_FRAME_TRANSFORMER_INTERFACE_H_