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
28namespace webrtc {
29namespace test {
30
31VoiceChannelTransport::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
46VoiceChannelTransport::~VoiceChannelTransport() {
47  voe_network_->DeRegisterExternalTransport(channel_);
48  UdpTransport::Destroy(socket_transport_);
49}
50
51void 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
60void 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
69int 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
78int VoiceChannelTransport::SetSendDestination(const char* ip_address,
79                                              uint16_t rtp_port) {
80  return socket_transport_->InitializeSendSockets(ip_address, rtp_port);
81}
82
83
84VideoChannelTransport::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
99VideoChannelTransport::~VideoChannelTransport() {
100  vie_network_->DeregisterSendTransport(channel_);
101  UdpTransport::Destroy(socket_transport_);
102}
103
104void 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
113void 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
122int 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
131int 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