Home | History | Annotate | Download | only in channel_transport
      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/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/voice_engine/include/voe_network.h"
     20 
     21 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
     22 #undef NDEBUG
     23 #include <assert.h>
     24 #endif
     25 
     26 namespace webrtc {
     27 namespace test {
     28 
     29 VoiceChannelTransport::VoiceChannelTransport(VoENetwork* voe_network,
     30                                              int channel)
     31     : channel_(channel),
     32       voe_network_(voe_network) {
     33   uint8_t socket_threads = 1;
     34   socket_transport_ = UdpTransport::Create(channel, socket_threads);
     35   int registered = voe_network_->RegisterExternalTransport(channel,
     36                                                            *socket_transport_);
     37 #if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS)
     38   EXPECT_EQ(0, registered);
     39 #else
     40   assert(registered == 0);
     41 #endif
     42 }
     43 
     44 VoiceChannelTransport::~VoiceChannelTransport() {
     45   voe_network_->DeRegisterExternalTransport(channel_);
     46   UdpTransport::Destroy(socket_transport_);
     47 }
     48 
     49 void VoiceChannelTransport::IncomingRTPPacket(
     50     const int8_t* incoming_rtp_packet,
     51     const size_t packet_length,
     52     const char* /*from_ip*/,
     53     const uint16_t /*from_port*/) {
     54   voe_network_->ReceivedRTPPacket(
     55       channel_, incoming_rtp_packet, packet_length, PacketTime());
     56 }
     57 
     58 void VoiceChannelTransport::IncomingRTCPPacket(
     59     const int8_t* incoming_rtcp_packet,
     60     const size_t packet_length,
     61     const char* /*from_ip*/,
     62     const uint16_t /*from_port*/) {
     63   voe_network_->ReceivedRTCPPacket(channel_, incoming_rtcp_packet,
     64                                    packet_length);
     65 }
     66 
     67 int VoiceChannelTransport::SetLocalReceiver(uint16_t rtp_port) {
     68   static const int kNumReceiveSocketBuffers = 500;
     69   int return_value = socket_transport_->InitializeReceiveSockets(this,
     70                                                                  rtp_port);
     71   if (return_value == 0) {
     72     return socket_transport_->StartReceiving(kNumReceiveSocketBuffers);
     73   }
     74   return return_value;
     75 }
     76 
     77 int VoiceChannelTransport::SetSendDestination(const char* ip_address,
     78                                               uint16_t rtp_port) {
     79   return socket_transport_->InitializeSendSockets(ip_address, rtp_port);
     80 }
     81 
     82 }  // namespace test
     83 }  // namespace webrtc
     84