2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
11 #include "webrtc/video_engine/vie_sender.h"
15 #include "webrtc/modules/utility/interface/rtp_dump.h"
16 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
17 #include "webrtc/system_wrappers/interface/trace.h"
21 ViESender::ViESender(int channel_id)
22 : channel_id_(channel_id),
23 critsect_(CriticalSectionWrapper::CreateCriticalSection()),
28 ViESender::~ViESender() {
31 RtpDump::DestroyRtpDump(rtp_dump_);
36 int ViESender::RegisterSendTransport(Transport* transport) {
37 CriticalSectionScoped cs(critsect_.get());
41 transport_ = transport;
45 int ViESender::DeregisterSendTransport() {
46 CriticalSectionScoped cs(critsect_.get());
47 if (transport_ == NULL) {
54 int ViESender::StartRTPDump(const char file_nameUTF8[1024]) {
55 CriticalSectionScoped cs(critsect_.get());
57 // Packet dump is already started, restart it.
60 rtp_dump_ = RtpDump::CreateRtpDump();
61 if (rtp_dump_ == NULL) {
62 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, channel_id_,
63 "StartSRTPDump: Failed to create RTP dump");
67 if (rtp_dump_->Start(file_nameUTF8) != 0) {
68 RtpDump::DestroyRtpDump(rtp_dump_);
70 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, channel_id_,
71 "StartRTPDump: Failed to start RTP dump");
77 int ViESender::StopRTPDump() {
78 CriticalSectionScoped cs(critsect_.get());
80 if (rtp_dump_->IsActive()) {
83 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, channel_id_,
84 "StopRTPDump: Dump not active");
86 RtpDump::DestroyRtpDump(rtp_dump_);
89 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, channel_id_,
90 "StopRTPDump: RTP dump not started");
96 int ViESender::SendPacket(int vie_id, const void* data, int len) {
97 CriticalSectionScoped cs(critsect_.get());
102 assert(ChannelId(vie_id) == channel_id_);
105 rtp_dump_->DumpPacket(static_cast<const uint8_t*>(data),
106 static_cast<uint16_t>(len));
109 const int bytes_sent = transport_->SendPacket(channel_id_, data, len);
110 if (bytes_sent != len) {
111 WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, channel_id_,
112 "ViESender::SendPacket - Transport failed to send RTP packet");
117 int ViESender::SendRTCPPacket(int vie_id, const void* data, int len) {
118 CriticalSectionScoped cs(critsect_.get());
122 assert(ChannelId(vie_id) == channel_id_);
125 rtp_dump_->DumpPacket(static_cast<const uint8_t*>(data),
126 static_cast<uint16_t>(len));
129 const int bytes_sent = transport_->SendRTCPPacket(channel_id_, data, len);
130 if (bytes_sent != len) {
132 webrtc::kTraceWarning, webrtc::kTraceVideo, channel_id_,
133 "ViESender::SendRTCPPacket - Transport failed to send RTCP packet"
134 " (%d vs %d)", bytes_sent, len);
139 } // namespace webrtc