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