blob: 587df47c66749eaf6079018b1d87c2ec79bdd41a [file] [log] [blame]
Benjamin Wrightea086912018-08-29 13:06:15 -07001/*
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_FRAMEDECRYPTORINTERFACE_H_
12#define API_CRYPTO_FRAMEDECRYPTORINTERFACE_H_
13
Benjamin Wright1f87ec62018-09-12 13:29:08 -070014#include <vector>
15
Benjamin Wrightea086912018-08-29 13:06:15 -070016#include "api/array_view.h"
17#include "api/mediatypes.h"
18#include "rtc_base/refcount.h"
19
20namespace webrtc {
21
22// FrameDecryptorInterface allows users to provide a custom decryption
23// implementation for all incoming audio and video frames. The user must also
24// provide a FrameEncryptorInterface to be able to encrypt the frames being
25// sent out of the device. Note this is an additional layer of encyrption in
26// addition to the standard SRTP mechanism and is not intended to be used
27// without it. You may assume that this interface will have the same lifetime
28// as the RTPReceiver it is attached to. It must only be attached to one
Benjamin Wright1f87ec62018-09-12 13:29:08 -070029// RTPReceiver. Additional data may be null.
Benjamin Wright88e3e3f2018-09-06 13:20:14 -070030// Note: This interface is not ready for production use.
Benjamin Wrightea086912018-08-29 13:06:15 -070031class FrameDecryptorInterface : public rtc::RefCountInterface {
32 public:
Benjamin Wrightd81ac952018-08-29 17:02:10 -070033 ~FrameDecryptorInterface() override {}
Benjamin Wrightea086912018-08-29 13:06:15 -070034
35 // Attempts to decrypt the encrypted frame. You may assume the frame size will
Benjamin Wright1f87ec62018-09-12 13:29:08 -070036 // be allocated to the size returned from GetMaxPlaintextSize. You may assume
37 // that the frames are in order if SRTP is enabled. The stream is not provided
38 // here and it is up to the implementor to transport this information to the
Benjamin Wright88e3e3f2018-09-06 13:20:14 -070039 // receiver if they care about it. You must set bytes_written to how many
40 // bytes you wrote to in the frame buffer. 0 must be returned if successful
41 // all other numbers can be selected by the implementer to represent error
42 // codes.
43 virtual int Decrypt(cricket::MediaType media_type,
Benjamin Wright1f87ec62018-09-12 13:29:08 -070044 const std::vector<uint32_t>& csrcs,
45 rtc::ArrayView<const uint8_t> additional_data,
Benjamin Wright88e3e3f2018-09-06 13:20:14 -070046 rtc::ArrayView<const uint8_t> encrypted_frame,
47 rtc::ArrayView<uint8_t> frame,
48 size_t* bytes_written) = 0;
Benjamin Wrightea086912018-08-29 13:06:15 -070049
50 // Returns the total required length in bytes for the output of the
Benjamin Wright88e3e3f2018-09-06 13:20:14 -070051 // decryption. This can be larger than the actual number of bytes you need but
52 // must never be smaller as it informs the size of the frame buffer.
53 virtual size_t GetMaxPlaintextByteSize(cricket::MediaType media_type,
54 size_t encrypted_frame_size) = 0;
Benjamin Wrightea086912018-08-29 13:06:15 -070055};
56
57} // namespace webrtc
58
59#endif // API_CRYPTO_FRAMEDECRYPTORINTERFACE_H_