blob: 6f27d9972a591f67004731b80733d2af2a863c6d [file] [log] [blame]
pbos@webrtc.org1ddd57f2013-09-18 11:52:42 +00001/*
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
pbos@webrtc.org24e20892013-10-28 16:32:01 +000011#include "webrtc/video/transport_adapter.h"
pbos@webrtc.org1ddd57f2013-09-18 11:52:42 +000012
13namespace webrtc {
14namespace internal {
15
16TransportAdapter::TransportAdapter(newapi::Transport* transport)
sprang@webrtc.org0a298152014-01-27 13:03:02 +000017 : transport_(transport), enabled_(0) {}
pbos@webrtc.org1ddd57f2013-09-18 11:52:42 +000018
19int TransportAdapter::SendPacket(int /*channel*/,
20 const void* packet,
21 int length) {
sprang@webrtc.org0a298152014-01-27 13:03:02 +000022 if (enabled_.Value() == 0)
23 return false;
24
pbos@webrtc.org3009c812013-11-20 12:17:04 +000025 bool success = transport_->SendRtp(static_cast<const uint8_t*>(packet),
pbos@webrtc.org1ddd57f2013-09-18 11:52:42 +000026 static_cast<size_t>(length));
27 return success ? length : -1;
28}
29
30int TransportAdapter::SendRTCPPacket(int /*channel*/,
31 const void* packet,
32 int length) {
sprang@webrtc.org0a298152014-01-27 13:03:02 +000033 if (enabled_.Value() == 0)
34 return false;
35
pbos@webrtc.org3009c812013-11-20 12:17:04 +000036 bool success = transport_->SendRtcp(static_cast<const uint8_t*>(packet),
pbos@webrtc.org1ddd57f2013-09-18 11:52:42 +000037 static_cast<size_t>(length));
38 return success ? length : -1;
39}
40
sprang@webrtc.org0a298152014-01-27 13:03:02 +000041void TransportAdapter::Enable() {
42 // If this exchange fails it means enabled_ was already true, no need to
43 // check result and iterate.
44 enabled_.CompareExchange(1, 0);
45}
46
47void TransportAdapter::Disable() { enabled_.CompareExchange(0, 1); }
48
pbos@webrtc.org1ddd57f2013-09-18 11:52:42 +000049} // namespace internal
50} // namespace webrtc