123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- #ifndef EXAMPLES_ANDROIDVOIP_JNI_ANDROID_VOIP_CLIENT_H_
- #define EXAMPLES_ANDROIDVOIP_JNI_ANDROID_VOIP_CLIENT_H_
- #include <jni.h>
- #include <memory>
- #include <string>
- #include <vector>
- #include "api/audio_codecs/audio_format.h"
- #include "api/call/transport.h"
- #include "api/voip/voip_base.h"
- #include "api/voip/voip_engine.h"
- #include "rtc_base/async_packet_socket.h"
- #include "rtc_base/async_udp_socket.h"
- #include "rtc_base/socket_address.h"
- #include "rtc_base/third_party/sigslot/sigslot.h"
- #include "rtc_base/thread.h"
- #include "sdk/android/native_api/jni/scoped_java_ref.h"
- namespace webrtc_examples {
- class AndroidVoipClient : public webrtc::Transport,
- public sigslot::has_slots<> {
- public:
-
-
-
-
-
- static AndroidVoipClient* Create(
- JNIEnv* env,
- const webrtc::JavaParamRef<jobject>& application_context,
- const webrtc::JavaParamRef<jobject>& j_voip_client);
- ~AndroidVoipClient() override;
-
-
- void GetSupportedCodecs(JNIEnv* env);
-
-
-
-
- void GetLocalIPAddress(JNIEnv* env);
-
- void SetEncoder(JNIEnv* env,
- const webrtc::JavaParamRef<jstring>& j_encoder_string);
-
- void SetDecoders(JNIEnv* env,
- const webrtc::JavaParamRef<jobject>& j_decoder_strings);
-
-
-
-
- void SetLocalAddress(JNIEnv* env,
- const webrtc::JavaParamRef<jstring>& j_ip_address_string,
- jint j_port_number_int);
- void SetRemoteAddress(
- JNIEnv* env,
- const webrtc::JavaParamRef<jstring>& j_ip_address_string,
- jint j_port_number_int);
-
-
-
- void StartSession(JNIEnv* env);
-
-
- void StopSession(JNIEnv* env);
-
-
-
- void StartSend(JNIEnv* env);
-
-
-
- void StopSend(JNIEnv* env);
-
-
-
- void StartPlayout(JNIEnv* env);
-
-
-
- void StopPlayout(JNIEnv* env);
-
- void Delete(JNIEnv* env);
-
- bool SendRtp(const uint8_t* packet,
- size_t length,
- const webrtc::PacketOptions& options) override;
- bool SendRtcp(const uint8_t* packet, size_t length) override;
-
- void OnSignalReadRTPPacket(rtc::AsyncPacketSocket* socket,
- const char* rtp_packet,
- size_t size,
- const rtc::SocketAddress& addr,
- const int64_t& timestamp);
- void OnSignalReadRTCPPacket(rtc::AsyncPacketSocket* socket,
- const char* rtcp_packet,
- size_t size,
- const rtc::SocketAddress& addr,
- const int64_t& timestamp);
- private:
- AndroidVoipClient(JNIEnv* env,
- const webrtc::JavaParamRef<jobject>& j_voip_client)
- : voip_thread_(rtc::Thread::CreateWithSocketServer()),
- j_voip_client_(env, j_voip_client) {}
- bool Init(JNIEnv* env,
- const webrtc::JavaParamRef<jobject>& application_context);
-
- void SetEncoder(const std::string& encoder);
- void SetDecoders(const std::vector<std::string>& decoders);
- void SetLocalAddress(const std::string& ip_address, const int port_number);
- void SetRemoteAddress(const std::string& ip_address, const int port_number);
-
-
-
- void SendRtpPacket(const std::vector<uint8_t>& packet_copy);
- void SendRtcpPacket(const std::vector<uint8_t>& packet_copy);
- void ReadRTPPacket(const std::vector<uint8_t>& packet_copy);
- void ReadRTCPPacket(const std::vector<uint8_t>& packet_copy);
-
- std::unique_ptr<rtc::Thread> voip_thread_;
-
-
- webrtc::ScopedJavaGlobalRef<jobject> j_voip_client_
- RTC_GUARDED_BY(voip_thread_);
-
-
- std::vector<webrtc::AudioCodecSpec> supported_codecs_
- RTC_GUARDED_BY(voip_thread_);
-
- JNIEnv* env_ RTC_GUARDED_BY(voip_thread_);
-
- std::unique_ptr<webrtc::VoipEngine> voip_engine_ RTC_GUARDED_BY(voip_thread_);
-
- absl::optional<webrtc::ChannelId> channel_ RTC_GUARDED_BY(voip_thread_);
-
- std::unique_ptr<rtc::AsyncUDPSocket> rtp_socket_ RTC_GUARDED_BY(voip_thread_);
- std::unique_ptr<rtc::AsyncUDPSocket> rtcp_socket_
- RTC_GUARDED_BY(voip_thread_);
- rtc::SocketAddress rtp_local_address_ RTC_GUARDED_BY(voip_thread_);
- rtc::SocketAddress rtcp_local_address_ RTC_GUARDED_BY(voip_thread_);
- rtc::SocketAddress rtp_remote_address_ RTC_GUARDED_BY(voip_thread_);
- rtc::SocketAddress rtcp_remote_address_ RTC_GUARDED_BY(voip_thread_);
- };
- }
- #endif
|