unity_plugin_apis.h 5.1 KB

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