From e3e07bf979eae09df2e161824573a457acf2212a Mon Sep 17 00:00:00 2001 From: Marina Ciocea Date: Thu, 27 Feb 2020 16:28:51 +0100 Subject: [PATCH] Introduce frame transformer interfaces for Insertable Streams Web API. Define FrameTransformerInterface for transforming encoded frames, and TransformedFrameCallback for receiving transformed frames. The FrameTransformerInterface will be implemented on the browser side, and will be set in WebRTC sender and receiver in follow up CLs: - Sender: https://webrtc-review.googlesource.com/c/src/+/169127 - Receiver: https://webrtc-review.googlesource.com/c/src/+/169129/1 Insertable Streams Web API explainer: https://github.com/alvestrand/webrtc-media-streams/blob/master/explainer.md Design doc for WebRTC library changes: http://doc/1eiLkjNUkRy2FssCPLUp6eH08BZuXXoHfbbBP1ZN7EVk Bug: webrtc:11380 Change-Id: Icf8ff159feb604f006e18157660f13d300a08b2b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/169126 Reviewed-by: Karl Wiberg Reviewed-by: Danil Chapovalov Commit-Queue: Marina Ciocea Cr-Commit-Position: refs/heads/master@{#30637} --- api/BUILD.gn | 11 ++++++ api/DEPS | 4 +++ api/frame_transformer_interface.h | 58 +++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 api/frame_transformer_interface.h diff --git a/api/BUILD.gn b/api/BUILD.gn index 517a0db0a0..b48247ce0f 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -162,6 +162,7 @@ rtc_library("libjingle_peerconnection_api") { ":audio_options_api", ":callfactory_api", ":fec_controller_api", + ":frame_transformer_interface", ":libjingle_logging_api", ":media_stream_interface", ":network_state_predictor_api", @@ -213,6 +214,16 @@ rtc_library("libjingle_peerconnection_api") { ] } +rtc_source_set("frame_transformer_interface") { + visibility = [ "*" ] + sources = [ "frame_transformer_interface.h" ] + deps = [ + ":scoped_refptr", + "../rtc_base:refcount", + "video:encoded_frame", + ] +} + rtc_library("rtc_error") { visibility = [ "*" ] sources = [ diff --git a/api/DEPS b/api/DEPS index ef9db30804..1e92b12281 100644 --- a/api/DEPS +++ b/api/DEPS @@ -90,6 +90,10 @@ specific_include_rules = { "+modules/include/module_fec_types.h", ], + "frame_transformer_interface\.h": [ + "+rtc_base/ref_count.h", + ], + "ice_transport_interface\.h": [ "+rtc_base/ref_count.h", ], diff --git a/api/frame_transformer_interface.h b/api/frame_transformer_interface.h new file mode 100644 index 0000000000..666a791f91 --- /dev/null +++ b/api/frame_transformer_interface.h @@ -0,0 +1,58 @@ +/* + * Copyright 2020 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef API_FRAME_TRANSFORMER_INTERFACE_H_ +#define API_FRAME_TRANSFORMER_INTERFACE_H_ + +#include +#include + +#include "api/scoped_refptr.h" +#include "api/video/encoded_frame.h" +#include "rtc_base/ref_count.h" + +namespace webrtc { + +// Objects implement this interface to be notified with the transformed frame. +class TransformedFrameCallback : public rtc::RefCountInterface { + public: + virtual void OnTransformedFrame( + std::unique_ptr transformed_frame) = 0; + + protected: + ~TransformedFrameCallback() override = default; +}; + +// Transformes encoded frames. The transformed frame is sent in a callback using +// the TransformedFrameCallback interface (see below). +class FrameTransformerInterface : public rtc::RefCountInterface { + public: + // Transforms |frame| using the implementing class' processing logic. + // |additional_data| holds data that is needed in the frame transformation + // logic, but is not included in |frame|; for example, when the transform + // function is used for encrypting/decrypting the frame, the additional data + // holds the serialized generic frame descriptor extension calculated in + // webrtc::RtpDescriptorAuthentication, needed in the encryption/decryption + // algorithms. + virtual void TransformFrame(std::unique_ptr frame, + std::vector additional_data, + uint32_t ssrc) = 0; + + virtual void RegisterTransformedFrameCallback( + rtc::scoped_refptr) = 0; + virtual void UnregisterTransformedFrameCallback() = 0; + + protected: + ~FrameTransformerInterface() override = default; +}; + +} // namespace webrtc + +#endif // API_FRAME_TRANSFORMER_INTERFACE_H_