-
Notifications
You must be signed in to change notification settings - Fork 169
/
snd_sample.cpp
66 lines (56 loc) · 1.97 KB
/
snd_sample.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ========================= eCAL LICENSE =================================
*/
/**
* @brief Sender thread for ecal samples
**/
#include <ecal/ecal.h>
#include "snd_sample.h"
#include "snd_raw_buffer.h"
namespace
{
size_t TransmitToUDP(const void* buf_, const size_t len_, const std::shared_ptr<eCAL::CUDPSender>& sample_sender_, const std::string& mcast_address_)
{
return (sample_sender_->Send(buf_, len_, mcast_address_.c_str()));
}
}
namespace eCAL
{
CSampleSender::CSampleSender(const SSenderAttr& attr_)
{
m_udp_sender = std::make_shared<CUDPSender>(attr_);
}
size_t CSampleSender::SendSample(const std::string& sample_name_, const eCAL::pb::Sample& ecal_sample_, long bandwidth_)
{
if (!m_udp_sender) return(0);
// return value
size_t sent_sum(0);
const size_t data_size = CreateSampleBuffer(sample_name_, ecal_sample_, m_payload);
if (data_size > 0)
{
// and send it
sent_sum = SendSampleBuffer(m_payload.data(), data_size, bandwidth_, std::bind(TransmitToUDP, std::placeholders::_1, std::placeholders::_2, m_udp_sender, m_attr.ipaddr));
#ifndef NDEBUG
// log it
eCAL::Logging::Log(log_level_debug4, "UDP Sample Buffer Sent (" + std::to_string(sent_sum) + " Bytes)");
#endif
}
// return bytes sent
return(sent_sum);
}
}