gyzhou | ad7cad8 | 2017-05-11 23:10:03 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 | // This file provides an example of unity native plugin APIs. |
| 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 13 | #ifndef EXAMPLES_UNITYPLUGIN_UNITY_PLUGIN_APIS_H_ |
| 14 | #define EXAMPLES_UNITYPLUGIN_UNITY_PLUGIN_APIS_H_ |
gyzhou | ad7cad8 | 2017-05-11 23:10:03 | [diff] [blame] | 15 | |
| 16 | #include <stdint.h> |
| 17 | |
gyzhou | b38f386 | 2017-07-25 23:04:31 | [diff] [blame] | 18 | // Definitions of callback functions. |
| 19 | typedef void (*I420FRAMEREADY_CALLBACK)(const uint8_t* data_y, |
| 20 | const uint8_t* data_u, |
| 21 | const uint8_t* data_v, |
Qiang Chen | 43fb912 | 2017-12-20 18:47:36 | [diff] [blame] | 22 | const uint8_t* data_a, |
gyzhou | b38f386 | 2017-07-25 23:04:31 | [diff] [blame] | 23 | int stride_y, |
| 24 | int stride_u, |
| 25 | int stride_v, |
Qiang Chen | 43fb912 | 2017-12-20 18:47:36 | [diff] [blame] | 26 | int stride_a, |
gyzhou | b38f386 | 2017-07-25 23:04:31 | [diff] [blame] | 27 | uint32_t width, |
| 28 | uint32_t height); |
gyzhou | ad7cad8 | 2017-05-11 23:10:03 | [diff] [blame] | 29 | typedef void (*LOCALDATACHANNELREADY_CALLBACK)(); |
| 30 | typedef void (*DATAFROMEDATECHANNELREADY_CALLBACK)(const char* msg); |
| 31 | typedef void (*FAILURE_CALLBACK)(const char* msg); |
gyzhou | b38f386 | 2017-07-25 23:04:31 | [diff] [blame] | 32 | typedef void (*LOCALSDPREADYTOSEND_CALLBACK)(const char* type, const char* sdp); |
| 33 | typedef void (*ICECANDIDATEREADYTOSEND_CALLBACK)(const char* candidate, |
Ali Tofigh | 6223809 | 2022-01-25 12:27:19 | [diff] [blame] | 34 | int sdp_mline_index, |
gyzhou | b38f386 | 2017-07-25 23:04:31 | [diff] [blame] | 35 | const char* sdp_mid); |
gyzhou | ad7cad8 | 2017-05-11 23:10:03 | [diff] [blame] | 36 | typedef void (*AUDIOBUSREADY_CALLBACK)(const void* audio_data, |
| 37 | int bits_per_sample, |
| 38 | int sample_rate, |
| 39 | int number_of_channels, |
| 40 | int number_of_frames); |
| 41 | |
qiangchen | 42f96d5 | 2017-08-09 00:08:03 | [diff] [blame] | 42 | #if defined(WEBRTC_WIN) |
gyzhou | ad7cad8 | 2017-05-11 23:10:03 | [diff] [blame] | 43 | #define WEBRTC_PLUGIN_API __declspec(dllexport) |
qiangchen | 42f96d5 | 2017-08-09 00:08:03 | [diff] [blame] | 44 | #elif defined(WEBRTC_ANDROID) |
| 45 | #define WEBRTC_PLUGIN_API __attribute__((visibility("default"))) |
| 46 | #endif |
gyzhou | ad7cad8 | 2017-05-11 23:10:03 | [diff] [blame] | 47 | extern "C" { |
| 48 | // Create a peerconnection and return a unique peer connection id. |
gyzhou | b38f386 | 2017-07-25 23:04:31 | [diff] [blame] | 49 | WEBRTC_PLUGIN_API int CreatePeerConnection(const char** turn_urls, |
Ali Tofigh | 6223809 | 2022-01-25 12:27:19 | [diff] [blame] | 50 | int no_of_urls, |
gyzhou | b38f386 | 2017-07-25 23:04:31 | [diff] [blame] | 51 | const char* username, |
Qiang Chen | 43fb912 | 2017-12-20 18:47:36 | [diff] [blame] | 52 | const char* credential, |
| 53 | bool mandatory_receive_video); |
gyzhou | ad7cad8 | 2017-05-11 23:10:03 | [diff] [blame] | 54 | // Close a peerconnection. |
| 55 | WEBRTC_PLUGIN_API bool ClosePeerConnection(int peer_connection_id); |
| 56 | // Add a audio stream. If audio_only is true, the stream only has an audio |
| 57 | // track and no video track. |
| 58 | WEBRTC_PLUGIN_API bool AddStream(int peer_connection_id, bool audio_only); |
| 59 | // Add a data channel to peer connection. |
| 60 | WEBRTC_PLUGIN_API bool AddDataChannel(int peer_connection_id); |
| 61 | // Create a peer connection offer. |
| 62 | WEBRTC_PLUGIN_API bool CreateOffer(int peer_connection_id); |
| 63 | // Create a peer connection answer. |
| 64 | WEBRTC_PLUGIN_API bool CreateAnswer(int peer_connection_id); |
| 65 | // Send data through data channel. |
| 66 | WEBRTC_PLUGIN_API bool SendDataViaDataChannel(int peer_connection_id, |
| 67 | const char* data); |
| 68 | // Set audio control. If is_mute=true, no audio will playout. If is_record=true, |
| 69 | // AUDIOBUSREADY_CALLBACK will be called every 10 ms. |
| 70 | WEBRTC_PLUGIN_API bool SetAudioControl(int peer_connection_id, |
| 71 | bool is_mute, |
| 72 | bool is_record); |
gyzhou | b38f386 | 2017-07-25 23:04:31 | [diff] [blame] | 73 | // Set remote sdp. |
| 74 | WEBRTC_PLUGIN_API bool SetRemoteDescription(int peer_connection_id, |
| 75 | const char* type, |
| 76 | const char* sdp); |
| 77 | // Add ice candidate. |
Ali Tofigh | 6223809 | 2022-01-25 12:27:19 | [diff] [blame] | 78 | WEBRTC_PLUGIN_API bool AddIceCandidate(int peer_connection_id, |
gyzhou | b38f386 | 2017-07-25 23:04:31 | [diff] [blame] | 79 | const char* candidate, |
Ali Tofigh | 6223809 | 2022-01-25 12:27:19 | [diff] [blame] | 80 | int sdp_mlineindex, |
gyzhou | b38f386 | 2017-07-25 23:04:31 | [diff] [blame] | 81 | const char* sdp_mid); |
gyzhou | ad7cad8 | 2017-05-11 23:10:03 | [diff] [blame] | 82 | |
| 83 | // Register callback functions. |
gyzhou | b38f386 | 2017-07-25 23:04:31 | [diff] [blame] | 84 | WEBRTC_PLUGIN_API bool RegisterOnLocalI420FrameReady( |
gyzhou | ad7cad8 | 2017-05-11 23:10:03 | [diff] [blame] | 85 | int peer_connection_id, |
gyzhou | b38f386 | 2017-07-25 23:04:31 | [diff] [blame] | 86 | I420FRAMEREADY_CALLBACK callback); |
| 87 | WEBRTC_PLUGIN_API bool RegisterOnRemoteI420FrameReady( |
| 88 | int peer_connection_id, |
| 89 | I420FRAMEREADY_CALLBACK callback); |
gyzhou | ad7cad8 | 2017-05-11 23:10:03 | [diff] [blame] | 90 | WEBRTC_PLUGIN_API bool RegisterOnLocalDataChannelReady( |
| 91 | int peer_connection_id, |
| 92 | LOCALDATACHANNELREADY_CALLBACK callback); |
| 93 | WEBRTC_PLUGIN_API bool RegisterOnDataFromDataChannelReady( |
| 94 | int peer_connection_id, |
| 95 | DATAFROMEDATECHANNELREADY_CALLBACK callback); |
| 96 | WEBRTC_PLUGIN_API bool RegisterOnFailure(int peer_connection_id, |
| 97 | FAILURE_CALLBACK callback); |
| 98 | WEBRTC_PLUGIN_API bool RegisterOnAudioBusReady(int peer_connection_id, |
| 99 | AUDIOBUSREADY_CALLBACK callback); |
| 100 | WEBRTC_PLUGIN_API bool RegisterOnLocalSdpReadytoSend( |
| 101 | int peer_connection_id, |
| 102 | LOCALSDPREADYTOSEND_CALLBACK callback); |
| 103 | WEBRTC_PLUGIN_API bool RegisterOnIceCandiateReadytoSend( |
| 104 | int peer_connection_id, |
| 105 | ICECANDIDATEREADYTOSEND_CALLBACK callback); |
gyzhou | ad7cad8 | 2017-05-11 23:10:03 | [diff] [blame] | 106 | } |
| 107 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 108 | #endif // EXAMPLES_UNITYPLUGIN_UNITY_PLUGIN_APIS_H_ |