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 13 #ifndef EXAMPLES_UNITYPLUGIN_UNITY_PLUGIN_APIS_H_ 14 #define EXAMPLES_UNITYPLUGIN_UNITY_PLUGIN_APIS_H_ 15 16 #include <stdint.h> 17 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 const uint8_t* data_a, 23 int stride_y, 24 int stride_u, 25 int stride_v, 26 int stride_a, 27 uint32_t width, 28 uint32_t height); 29 typedef void (*LOCALDATACHANNELREADY_CALLBACK)(); 30 typedef void (*DATAFROMEDATECHANNELREADY_CALLBACK)(const char* msg); 31 typedef void (*FAILURE_CALLBACK)(const char* msg); 32 typedef void (*LOCALSDPREADYTOSEND_CALLBACK)(const char* type, const char* sdp); 33 typedef void (*ICECANDIDATEREADYTOSEND_CALLBACK)(const char* candidate, 34 const int sdp_mline_index, 35 const char* sdp_mid); 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 42 #if defined(WEBRTC_WIN) 43 #define WEBRTC_PLUGIN_API __declspec(dllexport) 44 #elif defined(WEBRTC_ANDROID) 45 #define WEBRTC_PLUGIN_API __attribute__((visibility("default"))) 46 #endif 47 extern "C" { 48 // Create a peerconnection and return a unique peer connection id. 49 WEBRTC_PLUGIN_API int CreatePeerConnection(const char** turn_urls, 50 const int no_of_urls, 51 const char* username, 52 const char* credential, 53 bool mandatory_receive_video); 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); 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. 78 WEBRTC_PLUGIN_API bool AddIceCandidate(const int peer_connection_id, 79 const char* candidate, 80 const int sdp_mlineindex, 81 const char* sdp_mid); 82 83 // Register callback functions. 84 WEBRTC_PLUGIN_API bool RegisterOnLocalI420FrameReady( 85 int peer_connection_id, 86 I420FRAMEREADY_CALLBACK callback); 87 WEBRTC_PLUGIN_API bool RegisterOnRemoteI420FrameReady( 88 int peer_connection_id, 89 I420FRAMEREADY_CALLBACK callback); 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); 106 } 107 108 #endif // EXAMPLES_UNITYPLUGIN_UNITY_PLUGIN_APIS_H_ 109