1 /*
2 * Copyright (c) 2013 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 #include "webrtc/test/channel_transport/include/channel_transport.h"
12
13 #include <stdio.h>
14
15 #if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS)
16 #include "testing/gtest/include/gtest/gtest.h"
17 #endif
18 #include "webrtc/test/channel_transport/udp_transport.h"
19 #include "webrtc/video_engine/include/vie_network.h"
20 #include "webrtc/video_engine/vie_defines.h"
21 #include "webrtc/voice_engine/include/voe_network.h"
22
23 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
24 #undef NDEBUG
25 #include <assert.h>
26 #endif
27
28 namespace webrtc {
29 namespace test {
30
VoiceChannelTransport(VoENetwork * voe_network,int channel)31 VoiceChannelTransport::VoiceChannelTransport(VoENetwork* voe_network,
32 int channel)
33 : channel_(channel),
34 voe_network_(voe_network) {
35 uint8_t socket_threads = 1;
36 socket_transport_ = UdpTransport::Create(channel, socket_threads);
37 int registered = voe_network_->RegisterExternalTransport(channel,
38 *socket_transport_);
39 #if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS)
40 EXPECT_EQ(0, registered);
41 #else
42 assert(registered == 0);
43 #endif
44 }
45
~VoiceChannelTransport()46 VoiceChannelTransport::~VoiceChannelTransport() {
47 voe_network_->DeRegisterExternalTransport(channel_);
48 UdpTransport::Destroy(socket_transport_);
49 }
50
IncomingRTPPacket(const int8_t * incoming_rtp_packet,const int32_t packet_length,const char *,const uint16_t)51 void VoiceChannelTransport::IncomingRTPPacket(
52 const int8_t* incoming_rtp_packet,
53 const int32_t packet_length,
54 const char* /*from_ip*/,
55 const uint16_t /*from_port*/) {
56 voe_network_->ReceivedRTPPacket(
57 channel_, incoming_rtp_packet, packet_length, PacketTime());
58 }
59
IncomingRTCPPacket(const int8_t * incoming_rtcp_packet,const int32_t packet_length,const char *,const uint16_t)60 void VoiceChannelTransport::IncomingRTCPPacket(
61 const int8_t* incoming_rtcp_packet,
62 const int32_t packet_length,
63 const char* /*from_ip*/,
64 const uint16_t /*from_port*/) {
65 voe_network_->ReceivedRTCPPacket(channel_, incoming_rtcp_packet,
66 packet_length);
67 }
68
SetLocalReceiver(uint16_t rtp_port)69 int VoiceChannelTransport::SetLocalReceiver(uint16_t rtp_port) {
70 int return_value = socket_transport_->InitializeReceiveSockets(this,
71 rtp_port);
72 if (return_value == 0) {
73 return socket_transport_->StartReceiving(kViENumReceiveSocketBuffers);
74 }
75 return return_value;
76 }
77
SetSendDestination(const char * ip_address,uint16_t rtp_port)78 int VoiceChannelTransport::SetSendDestination(const char* ip_address,
79 uint16_t rtp_port) {
80 return socket_transport_->InitializeSendSockets(ip_address, rtp_port);
81 }
82
83
VideoChannelTransport(ViENetwork * vie_network,int channel)84 VideoChannelTransport::VideoChannelTransport(ViENetwork* vie_network,
85 int channel)
86 : channel_(channel),
87 vie_network_(vie_network) {
88 uint8_t socket_threads = 1;
89 socket_transport_ = UdpTransport::Create(channel, socket_threads);
90 int registered = vie_network_->RegisterSendTransport(channel,
91 *socket_transport_);
92 #if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS)
93 EXPECT_EQ(0, registered);
94 #else
95 assert(registered == 0);
96 #endif
97 }
98
~VideoChannelTransport()99 VideoChannelTransport::~VideoChannelTransport() {
100 vie_network_->DeregisterSendTransport(channel_);
101 UdpTransport::Destroy(socket_transport_);
102 }
103
IncomingRTPPacket(const int8_t * incoming_rtp_packet,const int32_t packet_length,const char *,const uint16_t)104 void VideoChannelTransport::IncomingRTPPacket(
105 const int8_t* incoming_rtp_packet,
106 const int32_t packet_length,
107 const char* /*from_ip*/,
108 const uint16_t /*from_port*/) {
109 vie_network_->ReceivedRTPPacket(
110 channel_, incoming_rtp_packet, packet_length, PacketTime());
111 }
112
IncomingRTCPPacket(const int8_t * incoming_rtcp_packet,const int32_t packet_length,const char *,const uint16_t)113 void VideoChannelTransport::IncomingRTCPPacket(
114 const int8_t* incoming_rtcp_packet,
115 const int32_t packet_length,
116 const char* /*from_ip*/,
117 const uint16_t /*from_port*/) {
118 vie_network_->ReceivedRTCPPacket(channel_, incoming_rtcp_packet,
119 packet_length);
120 }
121
SetLocalReceiver(uint16_t rtp_port)122 int VideoChannelTransport::SetLocalReceiver(uint16_t rtp_port) {
123 int return_value = socket_transport_->InitializeReceiveSockets(this,
124 rtp_port);
125 if (return_value == 0) {
126 return socket_transport_->StartReceiving(kViENumReceiveSocketBuffers);
127 }
128 return return_value;
129 }
130
SetSendDestination(const char * ip_address,uint16_t rtp_port)131 int VideoChannelTransport::SetSendDestination(const char* ip_address,
132 uint16_t rtp_port) {
133 return socket_transport_->InitializeSendSockets(ip_address, rtp_port);
134 }
135
136 } // namespace test
137 } // namespace webrtc
138