frame_encryptor_interface.h 2.5 KB

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