blob: 8b8fe0fe806a295f30177116bcda4e7ecdfc5f09 [file] [log] [blame]
gyzhouad7cad82017-05-11 23:10:031/*
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 Bonadei92ea95e2017-09-15 04:47:3113#ifndef EXAMPLES_UNITYPLUGIN_UNITY_PLUGIN_APIS_H_
14#define EXAMPLES_UNITYPLUGIN_UNITY_PLUGIN_APIS_H_
gyzhouad7cad82017-05-11 23:10:0315
16#include <stdint.h>
17
gyzhoub38f3862017-07-25 23:04:3118// Definitions of callback functions.
19typedef void (*I420FRAMEREADY_CALLBACK)(const uint8_t* data_y,
20 const uint8_t* data_u,
21 const uint8_t* data_v,
Qiang Chen43fb9122017-12-20 18:47:3622 const uint8_t* data_a,
gyzhoub38f3862017-07-25 23:04:3123 int stride_y,
24 int stride_u,
25 int stride_v,
Qiang Chen43fb9122017-12-20 18:47:3626 int stride_a,
gyzhoub38f3862017-07-25 23:04:3127 uint32_t width,
28 uint32_t height);
gyzhouad7cad82017-05-11 23:10:0329typedef void (*LOCALDATACHANNELREADY_CALLBACK)();
30typedef void (*DATAFROMEDATECHANNELREADY_CALLBACK)(const char* msg);
31typedef void (*FAILURE_CALLBACK)(const char* msg);
gyzhoub38f3862017-07-25 23:04:3132typedef void (*LOCALSDPREADYTOSEND_CALLBACK)(const char* type, const char* sdp);
33typedef void (*ICECANDIDATEREADYTOSEND_CALLBACK)(const char* candidate,
Ali Tofigh62238092022-01-25 12:27:1934 int sdp_mline_index,
gyzhoub38f3862017-07-25 23:04:3135 const char* sdp_mid);
gyzhouad7cad82017-05-11 23:10:0336typedef 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
qiangchen42f96d52017-08-09 00:08:0342#if defined(WEBRTC_WIN)
gyzhouad7cad82017-05-11 23:10:0343#define WEBRTC_PLUGIN_API __declspec(dllexport)
qiangchen42f96d52017-08-09 00:08:0344#elif defined(WEBRTC_ANDROID)
45#define WEBRTC_PLUGIN_API __attribute__((visibility("default")))
46#endif
gyzhouad7cad82017-05-11 23:10:0347extern "C" {
48// Create a peerconnection and return a unique peer connection id.
gyzhoub38f3862017-07-25 23:04:3149WEBRTC_PLUGIN_API int CreatePeerConnection(const char** turn_urls,
Ali Tofigh62238092022-01-25 12:27:1950 int no_of_urls,
gyzhoub38f3862017-07-25 23:04:3151 const char* username,
Qiang Chen43fb9122017-12-20 18:47:3652 const char* credential,
53 bool mandatory_receive_video);
gyzhouad7cad82017-05-11 23:10:0354// Close a peerconnection.
55WEBRTC_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.
58WEBRTC_PLUGIN_API bool AddStream(int peer_connection_id, bool audio_only);
59// Add a data channel to peer connection.
60WEBRTC_PLUGIN_API bool AddDataChannel(int peer_connection_id);
61// Create a peer connection offer.
62WEBRTC_PLUGIN_API bool CreateOffer(int peer_connection_id);
63// Create a peer connection answer.
64WEBRTC_PLUGIN_API bool CreateAnswer(int peer_connection_id);
65// Send data through data channel.
66WEBRTC_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.
70WEBRTC_PLUGIN_API bool SetAudioControl(int peer_connection_id,
71 bool is_mute,
72 bool is_record);
gyzhoub38f3862017-07-25 23:04:3173// Set remote sdp.
74WEBRTC_PLUGIN_API bool SetRemoteDescription(int peer_connection_id,
75 const char* type,
76 const char* sdp);
77// Add ice candidate.
Ali Tofigh62238092022-01-25 12:27:1978WEBRTC_PLUGIN_API bool AddIceCandidate(int peer_connection_id,
gyzhoub38f3862017-07-25 23:04:3179 const char* candidate,
Ali Tofigh62238092022-01-25 12:27:1980 int sdp_mlineindex,
gyzhoub38f3862017-07-25 23:04:3181 const char* sdp_mid);
gyzhouad7cad82017-05-11 23:10:0382
83// Register callback functions.
gyzhoub38f3862017-07-25 23:04:3184WEBRTC_PLUGIN_API bool RegisterOnLocalI420FrameReady(
gyzhouad7cad82017-05-11 23:10:0385 int peer_connection_id,
gyzhoub38f3862017-07-25 23:04:3186 I420FRAMEREADY_CALLBACK callback);
87WEBRTC_PLUGIN_API bool RegisterOnRemoteI420FrameReady(
88 int peer_connection_id,
89 I420FRAMEREADY_CALLBACK callback);
gyzhouad7cad82017-05-11 23:10:0390WEBRTC_PLUGIN_API bool RegisterOnLocalDataChannelReady(
91 int peer_connection_id,
92 LOCALDATACHANNELREADY_CALLBACK callback);
93WEBRTC_PLUGIN_API bool RegisterOnDataFromDataChannelReady(
94 int peer_connection_id,
95 DATAFROMEDATECHANNELREADY_CALLBACK callback);
96WEBRTC_PLUGIN_API bool RegisterOnFailure(int peer_connection_id,
97 FAILURE_CALLBACK callback);
98WEBRTC_PLUGIN_API bool RegisterOnAudioBusReady(int peer_connection_id,
99 AUDIOBUSREADY_CALLBACK callback);
100WEBRTC_PLUGIN_API bool RegisterOnLocalSdpReadytoSend(
101 int peer_connection_id,
102 LOCALSDPREADYTOSEND_CALLBACK callback);
103WEBRTC_PLUGIN_API bool RegisterOnIceCandiateReadytoSend(
104 int peer_connection_id,
105 ICECANDIDATEREADYTOSEND_CALLBACK callback);
gyzhouad7cad82017-05-11 23:10:03106}
107
Mirko Bonadei92ea95e2017-09-15 04:47:31108#endif // EXAMPLES_UNITYPLUGIN_UNITY_PLUGIN_APIS_H_