blob: 814b9675fb2e3fa75694a1aba026252312dd23e8 [file] [log] [blame]
gyzhouad7cad82017-05-11 16:10:03 -07001/*
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 06:47:31 +020013#ifndef EXAMPLES_UNITYPLUGIN_UNITY_PLUGIN_APIS_H_
14#define EXAMPLES_UNITYPLUGIN_UNITY_PLUGIN_APIS_H_
gyzhouad7cad82017-05-11 16:10:03 -070015
16#include <stdint.h>
17
gyzhoub38f3862017-07-25 16:04:31 -070018// 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,
22 int stride_y,
23 int stride_u,
24 int stride_v,
25 uint32_t width,
26 uint32_t height);
gyzhouad7cad82017-05-11 16:10:03 -070027typedef void (*LOCALDATACHANNELREADY_CALLBACK)();
28typedef void (*DATAFROMEDATECHANNELREADY_CALLBACK)(const char* msg);
29typedef void (*FAILURE_CALLBACK)(const char* msg);
gyzhoub38f3862017-07-25 16:04:31 -070030typedef void (*LOCALSDPREADYTOSEND_CALLBACK)(const char* type, const char* sdp);
31typedef void (*ICECANDIDATEREADYTOSEND_CALLBACK)(const char* candidate,
32 const int sdp_mline_index,
33 const char* sdp_mid);
gyzhouad7cad82017-05-11 16:10:03 -070034typedef 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
qiangchen42f96d52017-08-08 17:08:03 -070040#if defined(WEBRTC_WIN)
gyzhouad7cad82017-05-11 16:10:03 -070041#define WEBRTC_PLUGIN_API __declspec(dllexport)
qiangchen42f96d52017-08-08 17:08:03 -070042#elif defined(WEBRTC_ANDROID)
43#define WEBRTC_PLUGIN_API __attribute__((visibility("default")))
44#endif
gyzhouad7cad82017-05-11 16:10:03 -070045extern "C" {
46// Create a peerconnection and return a unique peer connection id.
gyzhoub38f3862017-07-25 16:04:31 -070047WEBRTC_PLUGIN_API int CreatePeerConnection(const char** turn_urls,
48 const int no_of_urls,
49 const char* username,
50 const char* credential);
gyzhouad7cad82017-05-11 16:10:03 -070051// Close a peerconnection.
52WEBRTC_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.
55WEBRTC_PLUGIN_API bool AddStream(int peer_connection_id, bool audio_only);
56// Add a data channel to peer connection.
57WEBRTC_PLUGIN_API bool AddDataChannel(int peer_connection_id);
58// Create a peer connection offer.
59WEBRTC_PLUGIN_API bool CreateOffer(int peer_connection_id);
60// Create a peer connection answer.
61WEBRTC_PLUGIN_API bool CreateAnswer(int peer_connection_id);
62// Send data through data channel.
63WEBRTC_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.
67WEBRTC_PLUGIN_API bool SetAudioControl(int peer_connection_id,
68 bool is_mute,
69 bool is_record);
gyzhoub38f3862017-07-25 16:04:31 -070070// Set remote sdp.
71WEBRTC_PLUGIN_API bool SetRemoteDescription(int peer_connection_id,
72 const char* type,
73 const char* sdp);
74// Add ice candidate.
75WEBRTC_PLUGIN_API bool AddIceCandidate(const int peer_connection_id,
76 const char* candidate,
77 const int sdp_mlineindex,
78 const char* sdp_mid);
gyzhouad7cad82017-05-11 16:10:03 -070079
80// Register callback functions.
gyzhoub38f3862017-07-25 16:04:31 -070081WEBRTC_PLUGIN_API bool RegisterOnLocalI420FrameReady(
gyzhouad7cad82017-05-11 16:10:03 -070082 int peer_connection_id,
gyzhoub38f3862017-07-25 16:04:31 -070083 I420FRAMEREADY_CALLBACK callback);
84WEBRTC_PLUGIN_API bool RegisterOnRemoteI420FrameReady(
85 int peer_connection_id,
86 I420FRAMEREADY_CALLBACK callback);
gyzhouad7cad82017-05-11 16:10:03 -070087WEBRTC_PLUGIN_API bool RegisterOnLocalDataChannelReady(
88 int peer_connection_id,
89 LOCALDATACHANNELREADY_CALLBACK callback);
90WEBRTC_PLUGIN_API bool RegisterOnDataFromDataChannelReady(
91 int peer_connection_id,
92 DATAFROMEDATECHANNELREADY_CALLBACK callback);
93WEBRTC_PLUGIN_API bool RegisterOnFailure(int peer_connection_id,
94 FAILURE_CALLBACK callback);
95WEBRTC_PLUGIN_API bool RegisterOnAudioBusReady(int peer_connection_id,
96 AUDIOBUSREADY_CALLBACK callback);
97WEBRTC_PLUGIN_API bool RegisterOnLocalSdpReadytoSend(
98 int peer_connection_id,
99 LOCALSDPREADYTOSEND_CALLBACK callback);
100WEBRTC_PLUGIN_API bool RegisterOnIceCandiateReadytoSend(
101 int peer_connection_id,
102 ICECANDIDATEREADYTOSEND_CALLBACK callback);
gyzhouad7cad82017-05-11 16:10:03 -0700103}
104
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200105#endif // EXAMPLES_UNITYPLUGIN_UNITY_PLUGIN_APIS_H_