1af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org/* 2af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 3af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org * 4af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org * Use of this source code is governed by a BSD-style license 5af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org * that can be found in the LICENSE file in the root of the source 6af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org * tree. An additional intellectual property rights grant can be found 7af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org * in the file PATENTS. All contributing project authors may 8af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org * be found in the AUTHORS file in the root of the source tree. 9af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org */ 10af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 11af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include "webrtc/test/channel_transport/include/channel_transport.h" 12af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 13af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <stdio.h> 14af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 15d8a5b0034b8a5ab0e45d162b2889f886f0ef1612sjlee@webrtc.org#if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS) 1696001c8e03bf364c81f5f86a2fadb371934d0383pbos@webrtc.org#include "testing/gtest/include/gtest/gtest.h" 17c075e2547e9da14bb80fb16c07fd64052d10dd9bpwestin@webrtc.org#endif 18af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include "webrtc/test/channel_transport/udp_transport.h" 19af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include "webrtc/video_engine/include/vie_network.h" 20af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include "webrtc/video_engine/vie_defines.h" 2196001c8e03bf364c81f5f86a2fadb371934d0383pbos@webrtc.org#include "webrtc/voice_engine/include/voe_network.h" 22af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 23d8a5b0034b8a5ab0e45d162b2889f886f0ef1612sjlee@webrtc.org#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) 246e816cb3c57519a49ae9a789fad84dc47a789f8efischman@webrtc.org#undef NDEBUG 256e816cb3c57519a49ae9a789fad84dc47a789f8efischman@webrtc.org#include <assert.h> 266e816cb3c57519a49ae9a789fad84dc47a789f8efischman@webrtc.org#endif 276e816cb3c57519a49ae9a789fad84dc47a789f8efischman@webrtc.org 28af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgnamespace webrtc { 29af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgnamespace test { 30af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 31af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgVoiceChannelTransport::VoiceChannelTransport(VoENetwork* voe_network, 32af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org int channel) 33af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org : channel_(channel), 34af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org voe_network_(voe_network) { 3591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint8_t socket_threads = 1; 36af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org socket_transport_ = UdpTransport::Create(channel, socket_threads); 376e816cb3c57519a49ae9a789fad84dc47a789f8efischman@webrtc.org int registered = voe_network_->RegisterExternalTransport(channel, 386e816cb3c57519a49ae9a789fad84dc47a789f8efischman@webrtc.org *socket_transport_); 39d8a5b0034b8a5ab0e45d162b2889f886f0ef1612sjlee@webrtc.org#if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS) 406e816cb3c57519a49ae9a789fad84dc47a789f8efischman@webrtc.org EXPECT_EQ(0, registered); 41c075e2547e9da14bb80fb16c07fd64052d10dd9bpwestin@webrtc.org#else 426e816cb3c57519a49ae9a789fad84dc47a789f8efischman@webrtc.org assert(registered == 0); 43c075e2547e9da14bb80fb16c07fd64052d10dd9bpwestin@webrtc.org#endif 44af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 45af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 46af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgVoiceChannelTransport::~VoiceChannelTransport() { 47af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org voe_network_->DeRegisterExternalTransport(channel_); 48af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpTransport::Destroy(socket_transport_); 49af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 50af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 51af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgvoid VoiceChannelTransport::IncomingRTPPacket( 5291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int8_t* incoming_rtp_packet, 5391cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t packet_length, 54af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org const char* /*from_ip*/, 5591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const uint16_t /*from_port*/) { 56fec6b6e5999edec8c90efae54357f1aae6a4c7ddsolenberg@webrtc.org voe_network_->ReceivedRTPPacket( 57fec6b6e5999edec8c90efae54357f1aae6a4c7ddsolenberg@webrtc.org channel_, incoming_rtp_packet, packet_length, PacketTime()); 58af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 59af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 60af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgvoid VoiceChannelTransport::IncomingRTCPPacket( 6191cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int8_t* incoming_rtcp_packet, 6291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t packet_length, 63af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org const char* /*from_ip*/, 6491cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const uint16_t /*from_port*/) { 65af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org voe_network_->ReceivedRTCPPacket(channel_, incoming_rtcp_packet, 66af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org packet_length); 67af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 68af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 6991cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint VoiceChannelTransport::SetLocalReceiver(uint16_t rtp_port) { 70c39749ad0ea83ae43dbf036984350bb84e9101ecpwestin@webrtc.org int return_value = socket_transport_->InitializeReceiveSockets(this, 71c39749ad0ea83ae43dbf036984350bb84e9101ecpwestin@webrtc.org rtp_port); 72c39749ad0ea83ae43dbf036984350bb84e9101ecpwestin@webrtc.org if (return_value == 0) { 73c39749ad0ea83ae43dbf036984350bb84e9101ecpwestin@webrtc.org return socket_transport_->StartReceiving(kViENumReceiveSocketBuffers); 74c39749ad0ea83ae43dbf036984350bb84e9101ecpwestin@webrtc.org } 75c39749ad0ea83ae43dbf036984350bb84e9101ecpwestin@webrtc.org return return_value; 76af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 77af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 78af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgint VoiceChannelTransport::SetSendDestination(const char* ip_address, 7991cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t rtp_port) { 80af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return socket_transport_->InitializeSendSockets(ip_address, rtp_port); 81af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 82af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 83af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 84af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgVideoChannelTransport::VideoChannelTransport(ViENetwork* vie_network, 85af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org int channel) 86af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org : channel_(channel), 87af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org vie_network_(vie_network) { 8891cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint8_t socket_threads = 1; 89af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org socket_transport_ = UdpTransport::Create(channel, socket_threads); 906e816cb3c57519a49ae9a789fad84dc47a789f8efischman@webrtc.org int registered = vie_network_->RegisterSendTransport(channel, 916e816cb3c57519a49ae9a789fad84dc47a789f8efischman@webrtc.org *socket_transport_); 92d8a5b0034b8a5ab0e45d162b2889f886f0ef1612sjlee@webrtc.org#if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS) 936e816cb3c57519a49ae9a789fad84dc47a789f8efischman@webrtc.org EXPECT_EQ(0, registered); 94c075e2547e9da14bb80fb16c07fd64052d10dd9bpwestin@webrtc.org#else 956e816cb3c57519a49ae9a789fad84dc47a789f8efischman@webrtc.org assert(registered == 0); 96c075e2547e9da14bb80fb16c07fd64052d10dd9bpwestin@webrtc.org#endif 97af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 986e816cb3c57519a49ae9a789fad84dc47a789f8efischman@webrtc.org 99af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgVideoChannelTransport::~VideoChannelTransport() { 100af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org vie_network_->DeregisterSendTransport(channel_); 101af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpTransport::Destroy(socket_transport_); 102af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 103af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 104af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgvoid VideoChannelTransport::IncomingRTPPacket( 10591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int8_t* incoming_rtp_packet, 10691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t packet_length, 107af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org const char* /*from_ip*/, 10891cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const uint16_t /*from_port*/) { 109efeb8ce7e183005e557a2d107203e2057cec26a8wu@webrtc.org vie_network_->ReceivedRTPPacket( 110efeb8ce7e183005e557a2d107203e2057cec26a8wu@webrtc.org channel_, incoming_rtp_packet, packet_length, PacketTime()); 111af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 112af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 113af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgvoid VideoChannelTransport::IncomingRTCPPacket( 11491cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int8_t* incoming_rtcp_packet, 11591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t packet_length, 116af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org const char* /*from_ip*/, 11791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const uint16_t /*from_port*/) { 118af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org vie_network_->ReceivedRTCPPacket(channel_, incoming_rtcp_packet, 119af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org packet_length); 120af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 121af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 12291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint VideoChannelTransport::SetLocalReceiver(uint16_t rtp_port) { 123af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org int return_value = socket_transport_->InitializeReceiveSockets(this, 124af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtp_port); 125af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (return_value == 0) { 126af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return socket_transport_->StartReceiving(kViENumReceiveSocketBuffers); 127af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 128af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return return_value; 129af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 130af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 131af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgint VideoChannelTransport::SetSendDestination(const char* ip_address, 13291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t rtp_port) { 133af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return socket_transport_->InitializeSendSockets(ip_address, rtp_port); 134af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 135af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 136af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} // namespace test 137af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} // namespace webrtc 138