2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-02-29 16:09:51 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
#include "video_engine/vie_network_impl.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2011-12-20 11:57:47 +00:00
|
|
|
#if (defined(WIN32_) || defined(WIN64_))
|
2011-07-07 08:21:25 +00:00
|
|
|
#include <qos.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-06-21 10:02:13 +00:00
|
|
|
#include "engine_configurations.h" // NOLINT
|
2011-12-20 11:57:47 +00:00
|
|
|
#include "system_wrappers/interface/trace.h"
|
2011-12-22 08:51:52 +00:00
|
|
|
#include "video_engine/include/vie_errors.h"
|
2011-12-20 11:57:47 +00:00
|
|
|
#include "video_engine/vie_channel.h"
|
|
|
|
|
#include "video_engine/vie_channel_manager.h"
|
|
|
|
|
#include "video_engine/vie_defines.h"
|
|
|
|
|
#include "video_engine/vie_encoder.h"
|
|
|
|
|
#include "video_engine/vie_impl.h"
|
2012-01-25 13:42:03 +00:00
|
|
|
#include "video_engine/vie_shared_data.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
namespace webrtc {
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
ViENetwork* ViENetwork::GetInterface(VideoEngine* video_engine) {
|
2011-07-07 08:21:25 +00:00
|
|
|
#ifdef WEBRTC_VIDEO_ENGINE_NETWORK_API
|
2011-12-20 11:57:47 +00:00
|
|
|
if (!video_engine) {
|
2011-07-07 08:21:25 +00:00
|
|
|
return NULL;
|
2011-12-20 11:57:47 +00:00
|
|
|
}
|
|
|
|
|
VideoEngineImpl* vie_impl = reinterpret_cast<VideoEngineImpl*>(video_engine);
|
|
|
|
|
ViENetworkImpl* vie_networkImpl = vie_impl;
|
|
|
|
|
// Increase ref count.
|
|
|
|
|
(*vie_networkImpl)++;
|
|
|
|
|
return vie_networkImpl;
|
|
|
|
|
#else
|
|
|
|
|
return NULL;
|
2011-07-07 08:21:25 +00:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::Release() {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo, shared_data_->instance_id(),
|
2011-12-20 11:57:47 +00:00
|
|
|
"ViENetwork::Release()");
|
|
|
|
|
// Decrease ref count.
|
|
|
|
|
(*this)--;
|
|
|
|
|
|
|
|
|
|
WebRtc_Word32 ref_count = GetCount();
|
|
|
|
|
if (ref_count < 0) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceWarning, kTraceVideo, shared_data_->instance_id(),
|
2011-12-20 11:57:47 +00:00
|
|
|
"ViENetwork release too many times");
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViEAPIDoesNotExist);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceInfo, kTraceVideo, shared_data_->instance_id(),
|
2011-12-20 11:57:47 +00:00
|
|
|
"ViENetwork reference count: %d", ref_count);
|
|
|
|
|
return ref_count;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-25 13:42:03 +00:00
|
|
|
ViENetworkImpl::ViENetworkImpl(ViESharedData* shared_data)
|
|
|
|
|
: shared_data_(shared_data) {
|
|
|
|
|
WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(),
|
2011-12-20 11:57:47 +00:00
|
|
|
"ViENetworkImpl::ViENetworkImpl() Ctor");
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
ViENetworkImpl::~ViENetworkImpl() {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(),
|
2011-12-20 11:57:47 +00:00
|
|
|
"ViENetworkImpl::~ViENetworkImpl() Dtor");
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::SetLocalReceiver(const int video_channel,
|
2012-06-21 10:02:13 +00:00
|
|
|
const uint16_t rtp_port,
|
|
|
|
|
const uint16_t rtcp_port,
|
2011-12-20 11:57:47 +00:00
|
|
|
const char* ip_address) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d, rtp_port: %u, rtcp_port: %u, ip_address: %s)",
|
|
|
|
|
__FUNCTION__, video_channel, rtp_port, rtcp_port, ip_address);
|
2012-01-25 13:42:03 +00:00
|
|
|
if (!shared_data_->Initialized()) {
|
|
|
|
|
shared_data_->SetLastError(kViENotInitialized);
|
|
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s - ViE instance %d not initialized", __FUNCTION__,
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->instance_id());
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
|
|
|
|
// The channel doesn't exists.
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"Channel doesn't exist");
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
if (vie_channel->Receiving()) {
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkAlreadyReceiving);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (vie_channel->SetLocalReceiver(rtp_port, rtcp_port, ip_address) != 0) {
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkUnknownError);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::GetLocalReceiver(const int video_channel,
|
2012-06-21 10:02:13 +00:00
|
|
|
uint16_t& rtp_port,
|
|
|
|
|
uint16_t& rtcp_port,
|
2011-12-20 11:57:47 +00:00
|
|
|
char* ip_address) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d)", __FUNCTION__, video_channel);
|
|
|
|
|
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"Channel doesn't exist");
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (vie_channel->GetLocalReceiver(rtp_port, rtcp_port, ip_address) != 0) {
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkLocalReceiverNotSet);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::SetSendDestination(const int video_channel,
|
|
|
|
|
const char* ip_address,
|
2012-06-21 10:02:13 +00:00
|
|
|
const uint16_t rtp_port,
|
|
|
|
|
const uint16_t rtcp_port,
|
|
|
|
|
const uint16_t source_rtp_port,
|
|
|
|
|
const uint16_t source_rtcp_port) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d, ip_address: %s, rtp_port: %u, rtcp_port: %u, "
|
|
|
|
|
"sourceRtpPort: %u, source_rtcp_port: %u)",
|
|
|
|
|
__FUNCTION__, video_channel, ip_address, rtp_port, rtcp_port,
|
|
|
|
|
source_rtp_port, source_rtcp_port);
|
2012-01-25 13:42:03 +00:00
|
|
|
if (!shared_data_->Initialized()) {
|
|
|
|
|
shared_data_->SetLastError(kViENotInitialized);
|
|
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s - ViE instance %d not initialized", __FUNCTION__,
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->instance_id());
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s Channel doesn't exist", __FUNCTION__);
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (vie_channel->Sending()) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s Channel already sending.", __FUNCTION__);
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkAlreadySending);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (vie_channel->SetSendDestination(ip_address, rtp_port, rtcp_port,
|
|
|
|
|
source_rtp_port,
|
|
|
|
|
source_rtcp_port) != 0) {
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkUnknownError);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::GetSendDestination(const int video_channel,
|
|
|
|
|
char* ip_address,
|
2012-06-21 10:02:13 +00:00
|
|
|
uint16_t& rtp_port,
|
|
|
|
|
uint16_t& rtcp_port,
|
|
|
|
|
uint16_t& source_rtp_port,
|
|
|
|
|
uint16_t& source_rtcp_port) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d)", __FUNCTION__, video_channel);
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
|
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
|
|
|
|
"Channel doesn't exist");
|
|
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (vie_channel->GetSendDestination(ip_address, rtp_port, rtcp_port,
|
|
|
|
|
source_rtp_port,
|
|
|
|
|
source_rtcp_port) != 0) {
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkDestinationNotSet);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::RegisterSendTransport(const int video_channel,
|
|
|
|
|
Transport& transport) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d)", __FUNCTION__, video_channel);
|
2012-01-25 13:42:03 +00:00
|
|
|
if (!shared_data_->Initialized()) {
|
|
|
|
|
shared_data_->SetLastError(kViENotInitialized);
|
|
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s - ViE instance %d not initialized", __FUNCTION__,
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->instance_id());
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s Channel doesn't exist", __FUNCTION__);
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (vie_channel->Sending()) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s Channel already sending.", __FUNCTION__);
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkAlreadySending);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (vie_channel->RegisterSendTransport(transport) != 0) {
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkUnknownError);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::DeregisterSendTransport(const int video_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d)", __FUNCTION__, video_channel);
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s Channel doesn't exist", __FUNCTION__);
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (vie_channel->Sending()) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s Channel already sending", __FUNCTION__);
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkAlreadySending);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (vie_channel->DeregisterSendTransport() != 0) {
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkUnknownError);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::ReceivedRTPPacket(const int video_channel, const void* data,
|
|
|
|
|
const int length) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d, data: -, length: %d)", __FUNCTION__,
|
|
|
|
|
video_channel, length);
|
2012-01-25 13:42:03 +00:00
|
|
|
if (!shared_data_->Initialized()) {
|
|
|
|
|
shared_data_->SetLastError(kViENotInitialized);
|
|
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s - ViE instance %d not initialized", __FUNCTION__,
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->instance_id());
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
|
|
|
|
// The channel doesn't exists
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"Channel doesn't exist");
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return vie_channel->ReceivedRTPPacket(data, length);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::ReceivedRTCPPacket(const int video_channel,
|
|
|
|
|
const void* data, const int length) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d, data: -, length: %d)", __FUNCTION__,
|
|
|
|
|
video_channel, length);
|
2012-01-25 13:42:03 +00:00
|
|
|
if (!shared_data_->Initialized()) {
|
|
|
|
|
shared_data_->SetLastError(kViENotInitialized);
|
|
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s - ViE instance %d not initialized", __FUNCTION__,
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->instance_id());
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"Channel doesn't exist");
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return vie_channel->ReceivedRTCPPacket(data, length);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::GetSourceInfo(const int video_channel,
|
2012-06-21 10:02:13 +00:00
|
|
|
uint16_t& rtp_port,
|
|
|
|
|
uint16_t& rtcp_port, char* ip_address,
|
2011-12-20 11:57:47 +00:00
|
|
|
unsigned int ip_address_length) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d)", __FUNCTION__, video_channel);
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"Channel doesn't exist");
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (vie_channel->GetSourceInfo(rtp_port, rtcp_port, ip_address,
|
|
|
|
|
ip_address_length) != 0) {
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkUnknownError);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::GetLocalIP(char ip_address[64], bool ipv6) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s( ip_address, ipV6: %d)", __FUNCTION__, ipv6);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
#ifndef WEBRTC_EXTERNAL_TRANSPORT
|
2012-01-25 13:42:03 +00:00
|
|
|
if (!shared_data_->Initialized()) {
|
|
|
|
|
shared_data_->SetLastError(kViENotInitialized);
|
|
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s - ViE instance %d not initialized", __FUNCTION__,
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->instance_id());
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
if (!ip_address) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s: No argument", __FUNCTION__);
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidArgument);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
WebRtc_UWord8 num_socket_threads = 1;
|
|
|
|
|
UdpTransport* socket_transport = UdpTransport::Create(
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEModuleId(shared_data_->instance_id(), -1), num_socket_threads);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
if (!socket_transport) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s: Could not create socket module", __FUNCTION__);
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkUnknownError);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-29 16:09:51 +00:00
|
|
|
char local_ip_address[64];
|
2011-12-20 11:57:47 +00:00
|
|
|
if (ipv6) {
|
2012-02-29 16:09:51 +00:00
|
|
|
char local_ip[16];
|
2011-12-20 11:57:47 +00:00
|
|
|
if (socket_transport->LocalHostAddressIPV6(local_ip) != 0) {
|
2012-01-17 12:18:16 +00:00
|
|
|
UdpTransport::Destroy(socket_transport);
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s: Could not get local IP", __FUNCTION__);
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkUnknownError);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
// Convert 128-bit address to character string (a:b:c:d:e:f:g:h).
|
2012-06-21 10:02:13 +00:00
|
|
|
// TODO(mflodman) Change sprintf.
|
|
|
|
|
sprintf(local_ip_address, // NOLINT
|
2011-12-20 11:57:47 +00:00
|
|
|
"%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:"
|
|
|
|
|
"%.2x%.2x",
|
|
|
|
|
local_ip[0], local_ip[1], local_ip[2], local_ip[3], local_ip[4],
|
|
|
|
|
local_ip[5], local_ip[6], local_ip[7], local_ip[8], local_ip[9],
|
|
|
|
|
local_ip[10], local_ip[11], local_ip[12], local_ip[13],
|
|
|
|
|
local_ip[14], local_ip[15]);
|
|
|
|
|
} else {
|
|
|
|
|
WebRtc_UWord32 local_ip = 0;
|
|
|
|
|
if (socket_transport->LocalHostAddress(local_ip) != 0) {
|
2012-01-17 12:18:16 +00:00
|
|
|
UdpTransport::Destroy(socket_transport);
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s: Could not get local IP", __FUNCTION__);
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkUnknownError);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
// Convert 32-bit address to character string (x.y.z.w).
|
2012-06-21 10:02:13 +00:00
|
|
|
// TODO(mflodman) Change sprintf.
|
|
|
|
|
sprintf(local_ip_address, "%d.%d.%d.%d", // NOLINT
|
2011-12-20 11:57:47 +00:00
|
|
|
static_cast<int>((local_ip >> 24) & 0x0ff),
|
|
|
|
|
static_cast<int>((local_ip >> 16) & 0x0ff),
|
|
|
|
|
static_cast<int>((local_ip >> 8) & 0x0ff),
|
|
|
|
|
static_cast<int>(local_ip & 0x0ff));
|
|
|
|
|
}
|
2012-06-21 10:02:13 +00:00
|
|
|
strncpy(ip_address, local_ip_address, sizeof(local_ip_address));
|
2011-12-20 11:57:47 +00:00
|
|
|
UdpTransport::Destroy(socket_transport);
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, ViEId(shared_data_->instance_id()),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s: local ip = %s", __FUNCTION__, local_ip_address);
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
#else
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, ViEId(shared_data_->instance_id()),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s: not available for external transport", __FUNCTION__);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
2011-07-07 08:21:25 +00:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::EnableIPv6(int video_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d)", __FUNCTION__, video_channel);
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"Channel doesn't exist");
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (vie_channel->EnableIPv6() != 0) {
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkUnknownError);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
bool ViENetworkImpl::IsIPv6Enabled(int video_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d)", __FUNCTION__, video_channel);
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"Channel doesn't exist");
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return vie_channel->IsIPv6Enabled();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::SetSourceFilter(const int video_channel,
|
2012-06-21 10:02:13 +00:00
|
|
|
const uint16_t rtp_port,
|
|
|
|
|
const uint16_t rtcp_port,
|
2011-12-20 11:57:47 +00:00
|
|
|
const char* ip_address) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d, rtp_port: %u, rtcp_port: %u, ip_address: %s)",
|
|
|
|
|
__FUNCTION__, video_channel, rtp_port, rtcp_port, ip_address);
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"Channel doesn't exist");
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (vie_channel->SetSourceFilter(rtp_port, rtcp_port, ip_address) != 0) {
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkUnknownError);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::GetSourceFilter(const int video_channel,
|
2012-06-21 10:02:13 +00:00
|
|
|
uint16_t& rtp_port,
|
|
|
|
|
uint16_t& rtcp_port,
|
2011-12-20 11:57:47 +00:00
|
|
|
char* ip_address) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d)", __FUNCTION__, video_channel);
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"Channel doesn't exist");
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (vie_channel->GetSourceFilter(rtp_port, rtcp_port, ip_address) != 0) {
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkUnknownError);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::SetSendToS(const int video_channel, const int DSCP,
|
|
|
|
|
const bool use_set_sockOpt = false) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d, DSCP: %d, use_set_sockOpt: %d)", __FUNCTION__,
|
|
|
|
|
video_channel, DSCP, use_set_sockOpt);
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"Channel doesn't exist");
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
#if defined(WEBRTC_LINUX) || defined(WEBRTC_MAC)
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceInfo, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
" force use_set_sockopt=true since there is no alternative"
|
|
|
|
|
" implementation");
|
|
|
|
|
if (vie_channel->SetToS(DSCP, true) != 0) {
|
2011-07-07 08:21:25 +00:00
|
|
|
#else
|
2011-12-20 11:57:47 +00:00
|
|
|
if (vie_channel->SetToS(DSCP, use_set_sockOpt) != 0) {
|
2011-07-07 08:21:25 +00:00
|
|
|
#endif
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkUnknownError);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-21 10:02:13 +00:00
|
|
|
int ViENetworkImpl::GetSendToS(const int video_channel,
|
|
|
|
|
int& DSCP, // NOLINT
|
|
|
|
|
bool& use_set_sockOpt) { // NOLINT
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d)", __FUNCTION__, video_channel);
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"Channel doesn't exist");
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (vie_channel->GetToS((WebRtc_Word32&) DSCP, use_set_sockOpt) != 0) {
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkUnknownError);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::SetSendGQoS(const int video_channel, const bool enable,
|
|
|
|
|
const int service_type,
|
|
|
|
|
const int overrideDSCP) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d, enable: %d, service_type: %d, "
|
|
|
|
|
"overrideDSCP: %d)", __FUNCTION__, video_channel, enable,
|
|
|
|
|
service_type, overrideDSCP);
|
2012-01-25 13:42:03 +00:00
|
|
|
if (!shared_data_->Initialized()) {
|
|
|
|
|
shared_data_->SetLastError(kViENotInitialized);
|
|
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s - ViE instance %d not initialized", __FUNCTION__,
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->instance_id());
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if (defined(WIN32_) || defined(WIN64_))
|
|
|
|
|
// Sanity check. We might crash if testing and relying on an OS socket error.
|
|
|
|
|
if (enable &&
|
|
|
|
|
(service_type != SERVICETYPE_BESTEFFORT) &&
|
|
|
|
|
(service_type != SERVICETYPE_CONTROLLEDLOAD) &&
|
|
|
|
|
(service_type != SERVICETYPE_GUARANTEED) &&
|
|
|
|
|
(service_type != SERVICETYPE_QUALITATIVE)) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s: service type %d not supported", __FUNCTION__,
|
|
|
|
|
video_channel, service_type);
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkServiceTypeNotSupported);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"Channel doesn't exist");
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
ViEEncoder* vie_encoder = cs.Encoder(video_channel);
|
|
|
|
|
if (!vie_encoder) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"Channel doesn't exist");
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
VideoCodec video_codec;
|
|
|
|
|
if (vie_encoder->GetEncoder(video_codec) != 0) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s: Could not get max bitrate for the channel",
|
2011-07-07 08:21:25 +00:00
|
|
|
__FUNCTION__);
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkSendCodecNotSet);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (vie_channel->SetSendGQoS(enable, service_type, video_codec.maxBitrate,
|
|
|
|
|
overrideDSCP) != 0) {
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkUnknownError);
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
2011-12-20 11:57:47 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
#else
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s: Not supported", __FUNCTION__);
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkNotSupported);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
2011-07-07 08:21:25 +00:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-21 10:02:13 +00:00
|
|
|
int ViENetworkImpl::GetSendGQoS(const int video_channel,
|
|
|
|
|
bool& enabled, // NOLINT
|
|
|
|
|
int& service_type, // NOLINT
|
|
|
|
|
int& overrideDSCP) { // NOLINT
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d)", __FUNCTION__, video_channel);
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"Channel doesn't exist");
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (vie_channel->GetSendGQoS(enabled, service_type, overrideDSCP) != 0) {
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkUnknownError);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::SetMTU(int video_channel, unsigned int mtu) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d, mtu: %u)", __FUNCTION__, video_channel, mtu);
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"Channel doesn't exist");
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (vie_channel->SetMTU(mtu) != 0) {
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkUnknownError);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::SetPacketTimeoutNotification(const int video_channel,
|
2011-07-07 08:21:25 +00:00
|
|
|
bool enable,
|
2011-12-20 11:57:47 +00:00
|
|
|
int timeout_seconds) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d, enable: %d, timeout_seconds: %u)",
|
|
|
|
|
__FUNCTION__, video_channel, enable, timeout_seconds);
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"Channel doesn't exist");
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (vie_channel->SetPacketTimeoutNotification(enable,
|
|
|
|
|
timeout_seconds) != 0) {
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkUnknownError);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::RegisterObserver(const int video_channel,
|
|
|
|
|
ViENetworkObserver& observer) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d)", __FUNCTION__, video_channel);
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"Channel doesn't exist");
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (vie_channel->RegisterNetworkObserver(&observer) != 0) {
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkObserverAlreadyRegistered);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::DeregisterObserver(const int video_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d)", __FUNCTION__, video_channel);
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"Channel doesn't exist");
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (!vie_channel->NetworkObserverRegistered()) {
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkObserverNotRegistered);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return vie_channel->RegisterNetworkObserver(NULL);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::SetPeriodicDeadOrAliveStatus(
|
|
|
|
|
const int video_channel,
|
|
|
|
|
bool enable,
|
|
|
|
|
unsigned int sample_time_seconds) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d, enable: %d, sample_time_seconds: %ul)",
|
|
|
|
|
__FUNCTION__, video_channel, enable, sample_time_seconds);
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"Channel doesn't exist");
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (!vie_channel->NetworkObserverRegistered()) {
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkObserverNotRegistered);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (vie_channel->SetPeriodicDeadOrAliveStatus(enable, sample_time_seconds)
|
|
|
|
|
!= 0) {
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkUnknownError);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 11:57:47 +00:00
|
|
|
int ViENetworkImpl::SendUDPPacket(const int video_channel, const void* data,
|
2011-07-07 08:21:25 +00:00
|
|
|
const unsigned int length,
|
2011-12-20 11:57:47 +00:00
|
|
|
int& transmitted_bytes,
|
|
|
|
|
bool use_rtcp_socket = false) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s(channel: %d, data: -, length: %d, transmitter_bytes: -, "
|
|
|
|
|
"useRtcpSocket: %d)", __FUNCTION__, video_channel, length,
|
|
|
|
|
use_rtcp_socket);
|
2012-01-25 13:42:03 +00:00
|
|
|
if (!shared_data_->Initialized()) {
|
|
|
|
|
shared_data_->SetLastError(kViENotInitialized);
|
|
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
|
2011-12-20 11:57:47 +00:00
|
|
|
"%s - ViE instance %d not initialized", __FUNCTION__,
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->instance_id());
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2012-01-25 13:42:03 +00:00
|
|
|
ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
|
2011-12-20 11:57:47 +00:00
|
|
|
ViEChannel* vie_channel = cs.Channel(video_channel);
|
|
|
|
|
if (!vie_channel) {
|
2012-01-25 13:42:03 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
|
|
|
|
ViEId(shared_data_->instance_id(), video_channel),
|
2011-12-20 11:57:47 +00:00
|
|
|
"Channel doesn't exist");
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkInvalidChannelId);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (vie_channel->SendUDPPacket((const WebRtc_Word8*) data, length,
|
|
|
|
|
(WebRtc_Word32&) transmitted_bytes,
|
|
|
|
|
use_rtcp_socket) < 0) {
|
2012-01-25 13:42:03 +00:00
|
|
|
shared_data_->SetLastError(kViENetworkUnknownError);
|
2011-12-20 11:57:47 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2011-12-20 11:57:47 +00:00
|
|
|
|
|
|
|
|
} // namespace webrtc
|