1 /* 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 "api/video/video_frame_metadata.h" 20 #include "rtc_base/ref_count.h" 21 22 namespace webrtc { 23 24 // Owns the frame payload data. 25 class 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 33 // Copies |data| into the owned frame payload data. 34 virtual void SetData(rtc::ArrayView<const uint8_t> data) = 0; 35 36 virtual uint32_t GetTimestamp() const = 0; 37 virtual uint32_t GetSsrc() const = 0; 38 }; 39 40 class TransformableVideoFrameInterface : public TransformableFrameInterface { 41 public: 42 virtual ~TransformableVideoFrameInterface() = default; 43 virtual bool IsKeyFrame() const = 0; 44 45 // Returns data needed in the frame transformation logic; for example, 46 // when the transformation applied to the frame is encryption/decryption, the 47 // additional data holds the serialized generic frame descriptor extension 48 // calculated in webrtc::RtpDescriptorAuthentication. 49 // TODO(bugs.webrtc.org/11380) remove from interface once 50 // webrtc::RtpDescriptorAuthentication is exposed in api/. 51 virtual std::vector<uint8_t> GetAdditionalData() const = 0; 52 53 virtual const VideoFrameMetadata& GetMetadata() const = 0; 54 }; 55 56 // Extends the TransformableFrameInterface to expose audio-specific information. 57 class TransformableAudioFrameInterface : public TransformableFrameInterface { 58 public: 59 virtual ~TransformableAudioFrameInterface() = default; 60 61 // Exposes the frame header, enabling the interface clients to use the 62 // information in the header as needed, for example to compile the list of 63 // csrcs. 64 virtual const RTPHeader& GetHeader() const = 0; 65 }; 66 67 // Objects implement this interface to be notified with the transformed frame. 68 class TransformedFrameCallback : public rtc::RefCountInterface { 69 public: 70 virtual void OnTransformedFrame( 71 std::unique_ptr<TransformableFrameInterface> frame) = 0; 72 73 protected: 74 ~TransformedFrameCallback() override = default; 75 }; 76 77 // Transforms encoded frames. The transformed frame is sent in a callback using 78 // the TransformedFrameCallback interface (see above). 79 class FrameTransformerInterface : public rtc::RefCountInterface { 80 public: 81 // Transforms |frame| using the implementing class' processing logic. 82 virtual void Transform( 83 std::unique_ptr<TransformableFrameInterface> transformable_frame) = 0; 84 RegisterTransformedFrameCallback(rtc::scoped_refptr<TransformedFrameCallback>)85 virtual void RegisterTransformedFrameCallback( 86 rtc::scoped_refptr<TransformedFrameCallback>) {} RegisterTransformedFrameSinkCallback(rtc::scoped_refptr<TransformedFrameCallback>,uint32_t ssrc)87 virtual void RegisterTransformedFrameSinkCallback( 88 rtc::scoped_refptr<TransformedFrameCallback>, 89 uint32_t ssrc) {} UnregisterTransformedFrameCallback()90 virtual void UnregisterTransformedFrameCallback() {} UnregisterTransformedFrameSinkCallback(uint32_t ssrc)91 virtual void UnregisterTransformedFrameSinkCallback(uint32_t ssrc) {} 92 93 protected: 94 ~FrameTransformerInterface() override = default; 95 }; 96 97 } // namespace webrtc 98 99 #endif // API_FRAME_TRANSFORMER_INTERFACE_H_ 100