blob: 5bbcffe28ee56bedf8c46670cd119b0253725cc2 [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>
Philipp Hancke0bace222023-10-23 09:57:4315#include <string>
Marina Cioceae3e07bf2020-02-27 15:28:5116
Harald Alvestrande8a2b3c2023-10-31 13:30:3017#include "api/ref_count.h"
Marina Cioceae3e07bf2020-02-27 15:28:5118#include "api/scoped_refptr.h"
19#include "api/video/encoded_frame.h"
Marina Cioceacdc89b42020-05-14 18:01:0220#include "api/video/video_frame_metadata.h"
Marina Cioceae3e07bf2020-02-27 15:28:5121
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 Herreb4062e52023-06-29 09:02:2239 virtual void SetRTPTimestamp(uint32_t timestamp) = 0;
40
Palak Agarwala09f21b2023-02-22 13:46:2341 // TODO(https://bugs.webrtc.org/14878): Change this to pure virtual after it
42 // is implemented everywhere.
43 virtual absl::optional<Timestamp> GetCaptureTimeIdentifier() const {
44 return absl::nullopt;
45 }
Tony Herre8fb41a32021-09-24 12:05:2046
47 enum class Direction {
48 kUnknown,
49 kReceiver,
50 kSender,
51 };
52 // TODO(crbug.com/1250638): Remove this distinction between receiver and
53 // sender frames to allow received frames to be directly re-transmitted on
54 // other PeerConnectionss.
55 virtual Direction GetDirection() const { return Direction::kUnknown; }
Philipp Hancke3e3881a2023-11-06 10:28:3056 virtual std::string GetMimeType() const = 0;
Marina Cioceac24b6b72020-03-30 12:51:1057};
58
59class TransformableVideoFrameInterface : public TransformableFrameInterface {
60 public:
61 virtual ~TransformableVideoFrameInterface() = default;
62 virtual bool IsKeyFrame() const = 0;
63
Tony Herre6d262c52023-02-24 11:20:2864 virtual VideoFrameMetadata Metadata() const = 0;
65
Tony Herrec381c332023-04-13 07:37:5566 virtual void SetMetadata(const VideoFrameMetadata&) = 0;
Marina Cioceac24b6b72020-03-30 12:51:1067};
68
Marina Ciocea48623202020-04-01 08:19:4469// Extends the TransformableFrameInterface to expose audio-specific information.
70class TransformableAudioFrameInterface : public TransformableFrameInterface {
71 public:
72 virtual ~TransformableAudioFrameInterface() = default;
73
Sergio Garcia Murillo15dfc5a2022-10-11 10:34:4474 virtual rtc::ArrayView<const uint32_t> GetContributingSources() const = 0;
Tony Herre097a4de2023-06-19 15:13:0875
76 // TODO(crbug.com/1453226): Change this to pure virtual after it
77 // is implemented everywhere.
78 virtual const absl::optional<uint16_t> SequenceNumber() const {
79 return absl::nullopt;
80 }
Tony Herrefc68f1f2023-06-22 13:32:2481
Palak Agarwal05051152023-09-20 08:01:1882 virtual absl::optional<uint64_t> AbsoluteCaptureTimestamp() const = 0;
Tony Herrefc68f1f2023-06-22 13:32:2483
84 enum class FrameType { kEmptyFrame, kAudioFrameSpeech, kAudioFrameCN };
85
86 // TODO(crbug.com/1456628): Change this to pure virtual after it
87 // is implemented everywhere.
88 virtual FrameType Type() const { return FrameType::kEmptyFrame; }
Marina Ciocea48623202020-04-01 08:19:4489};
90
Marina Cioceae3e07bf2020-02-27 15:28:5191// Objects implement this interface to be notified with the transformed frame.
92class TransformedFrameCallback : public rtc::RefCountInterface {
93 public:
94 virtual void OnTransformedFrame(
Marina Ciocea81be4212020-05-05 14:03:5495 std::unique_ptr<TransformableFrameInterface> frame) = 0;
Marina Cioceae3e07bf2020-02-27 15:28:5196
Tony Herre6e956052023-11-16 13:59:5497 // Request to no longer be called on each frame, instead having frames be
98 // sent directly to OnTransformedFrame without additional work.
99 // TODO(crbug.com/1502781): Make pure virtual once all mocks have
100 // implementations.
101 virtual void StartShortCircuiting() {}
102
Marina Cioceae3e07bf2020-02-27 15:28:51103 protected:
104 ~TransformedFrameCallback() override = default;
105};
106
Marina Cioceac24b6b72020-03-30 12:51:10107// Transforms encoded frames. The transformed frame is sent in a callback using
108// the TransformedFrameCallback interface (see above).
Marina Cioceae3e07bf2020-02-27 15:28:51109class FrameTransformerInterface : public rtc::RefCountInterface {
110 public:
Artem Titov0e61fdd2021-07-25 19:50:14111 // Transforms `frame` using the implementing class' processing logic.
Marina Cioceac24b6b72020-03-30 12:51:10112 virtual void Transform(
Marina Ciocea81be4212020-05-05 14:03:54113 std::unique_ptr<TransformableFrameInterface> transformable_frame) = 0;
Marina Cioceae3e07bf2020-02-27 15:28:51114
115 virtual void RegisterTransformedFrameCallback(
Marina Cioceafdabfbc2020-04-10 16:40:11116 rtc::scoped_refptr<TransformedFrameCallback>) {}
117 virtual void RegisterTransformedFrameSinkCallback(
118 rtc::scoped_refptr<TransformedFrameCallback>,
119 uint32_t ssrc) {}
120 virtual void UnregisterTransformedFrameCallback() {}
121 virtual void UnregisterTransformedFrameSinkCallback(uint32_t ssrc) {}
Marina Cioceae3e07bf2020-02-27 15:28:51122
123 protected:
124 ~FrameTransformerInterface() override = default;
125};
126
127} // namespace webrtc
128
129#endif // API_FRAME_TRANSFORMER_INTERFACE_H_