frame_encryptor_interface.h (2558B)
1 /* 2 * Copyright 2018 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_CRYPTO_FRAME_ENCRYPTOR_INTERFACE_H_ 12 #define API_CRYPTO_FRAME_ENCRYPTOR_INTERFACE_H_ 13 14 #include <cstddef> 15 #include <cstdint> 16 17 #include "api/array_view.h" 18 #include "api/media_types.h" 19 #include "api/ref_count.h" 20 21 namespace webrtc { 22 23 // FrameEncryptorInterface allows users to provide a custom encryption 24 // implementation to encrypt all outgoing audio and video frames. The user must 25 // also provide a FrameDecryptorInterface to be able to decrypt the frames on 26 // the receiving device. Note this is an additional layer of encryption in 27 // addition to the standard SRTP mechanism and is not intended to be used 28 // without it. Implementations of this interface will have the same lifetime as 29 // the RTPSenders it is attached to. Additional data may be null. 30 class FrameEncryptorInterface : public RefCountInterface { 31 public: 32 ~FrameEncryptorInterface() override {} 33 34 // Attempts to encrypt the provided frame. You may assume the encrypted_frame 35 // will match the size returned by GetMaxCiphertextByteSize for a give frame. 36 // You may assume that the frames will arrive in order if SRTP is enabled. 37 // The ssrc will simply identify which stream the frame is travelling on. You 38 // must set bytes_written to the number of bytes you wrote in the 39 // encrypted_frame. 0 must be returned if successful all other numbers can be 40 // selected by the implementer to represent error codes. 41 virtual int Encrypt(MediaType media_type, 42 uint32_t ssrc, 43 ArrayView<const uint8_t> additional_data, 44 ArrayView<const uint8_t> frame, 45 ArrayView<uint8_t> encrypted_frame, 46 size_t* bytes_written) = 0; 47 48 // Returns the total required length in bytes for the output of the 49 // encryption. This can be larger than the actual number of bytes you need but 50 // must never be smaller as it informs the size of the encrypted_frame buffer. 51 virtual size_t GetMaxCiphertextByteSize(MediaType media_type, 52 size_t frame_size) = 0; 53 }; 54 55 } // namespace webrtc 56 57 #endif // API_CRYPTO_FRAME_ENCRYPTOR_INTERFACE_H_