| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2012 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 "voice_engine/voe_network_impl.h" | |
| 12 | |
| 13 #include "rtc_base/checks.h" | |
| 14 #include "rtc_base/format_macros.h" | |
| 15 #include "rtc_base/logging.h" | |
| 16 #include "voice_engine/channel.h" | |
| 17 #include "voice_engine/include/voe_errors.h" | |
| 18 #include "voice_engine/voice_engine_impl.h" | |
| 19 | |
| 20 namespace webrtc { | |
| 21 | |
| 22 VoENetwork* VoENetwork::GetInterface(VoiceEngine* voiceEngine) { | |
| 23 if (!voiceEngine) { | |
| 24 return nullptr; | |
| 25 } | |
| 26 VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine); | |
| 27 s->AddRef(); | |
| 28 return s; | |
| 29 } | |
| 30 | |
| 31 VoENetworkImpl::VoENetworkImpl(voe::SharedData* shared) : _shared(shared) { | |
| 32 } | |
| 33 | |
| 34 VoENetworkImpl::~VoENetworkImpl() = default; | |
| 35 | |
| 36 int VoENetworkImpl::RegisterExternalTransport(int channel, | |
| 37 Transport& transport) { | |
| 38 RTC_DCHECK(_shared->statistics().Initialized()); | |
| 39 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); | |
| 40 voe::Channel* channelPtr = ch.channel(); | |
| 41 if (!channelPtr) { | |
| 42 LOG_F(LS_ERROR) << "Failed to locate channel: " << channel; | |
| 43 return -1; | |
| 44 } | |
| 45 return channelPtr->RegisterExternalTransport(&transport); | |
| 46 } | |
| 47 | |
| 48 int VoENetworkImpl::DeRegisterExternalTransport(int channel) { | |
| 49 RTC_CHECK(_shared->statistics().Initialized()); | |
| 50 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); | |
| 51 voe::Channel* channelPtr = ch.channel(); | |
| 52 if (!channelPtr) { | |
| 53 LOG_F(LS_ERROR) << "Failed to locate channel: " << channel; | |
| 54 return -1; | |
| 55 } | |
| 56 return channelPtr->DeRegisterExternalTransport(); | |
| 57 } | |
| 58 | |
| 59 int VoENetworkImpl::ReceivedRTPPacket(int channel, | |
| 60 const void* data, | |
| 61 size_t length) { | |
| 62 return ReceivedRTPPacket(channel, data, length, webrtc::PacketTime()); | |
| 63 } | |
| 64 | |
| 65 int VoENetworkImpl::ReceivedRTPPacket(int channel, | |
| 66 const void* data, | |
| 67 size_t length, | |
| 68 const PacketTime& packet_time) { | |
| 69 RTC_CHECK(_shared->statistics().Initialized()); | |
| 70 RTC_CHECK(data); | |
| 71 // L16 at 32 kHz, stereo, 10 ms frames (+12 byte RTP header) -> 1292 bytes | |
| 72 if ((length < 12) || (length > 1292)) { | |
| 73 LOG_F(LS_ERROR) << "Invalid packet length: " << length; | |
| 74 return -1; | |
| 75 } | |
| 76 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); | |
| 77 voe::Channel* channelPtr = ch.channel(); | |
| 78 if (!channelPtr) { | |
| 79 LOG_F(LS_ERROR) << "Failed to locate channel: " << channel; | |
| 80 return -1; | |
| 81 } | |
| 82 if (!channelPtr->ExternalTransport()) { | |
| 83 LOG_F(LS_ERROR) << "No external transport for channel: " << channel; | |
| 84 return -1; | |
| 85 } | |
| 86 return channelPtr->ReceivedRTPPacket(static_cast<const uint8_t*>(data), | |
| 87 length, packet_time); | |
| 88 } | |
| 89 | |
| 90 int VoENetworkImpl::ReceivedRTCPPacket(int channel, | |
| 91 const void* data, | |
| 92 size_t length) { | |
| 93 RTC_CHECK(_shared->statistics().Initialized()); | |
| 94 RTC_CHECK(data); | |
| 95 if (length < 4) { | |
| 96 LOG_F(LS_ERROR) << "Invalid packet length: " << length; | |
| 97 return -1; | |
| 98 } | |
| 99 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); | |
| 100 voe::Channel* channelPtr = ch.channel(); | |
| 101 if (!channelPtr) { | |
| 102 LOG_F(LS_ERROR) << "Failed to locate channel: " << channel; | |
| 103 return -1; | |
| 104 } | |
| 105 if (!channelPtr->ExternalTransport()) { | |
| 106 LOG_F(LS_ERROR) << "No external transport for channel: " << channel; | |
| 107 return -1; | |
| 108 } | |
| 109 return channelPtr->ReceivedRTCPPacket(static_cast<const uint8_t*>(data), | |
| 110 length); | |
| 111 } | |
| 112 | |
| 113 } // namespace webrtc | |
| OLD | NEW |