libflute
Transmitter.h
Go to the documentation of this file.
1 // libflute - FLUTE/ALC library
2 //
3 // Copyright (C) 2021 Klaus Kühnhammer (Österreichische Rundfunksender GmbH & Co KG)
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Affero General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Affero General Public License for more details.
14 //
15 // You should have received a copy of the GNU Affero General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 
19 #pragma once
20 #include <boost/asio.hpp>
21 #include <boost/bind.hpp>
22 #include <queue>
23 #include <string>
24 #include <map>
25 #include <mutex>
26 #include "File.h"
27 #include "AlcPacket.h"
28 #include "FileDeliveryTable.h"
29 
30 namespace LibFlute {
34  class Transmitter {
35  public:
42  typedef std::function<void(uint32_t)> completion_callback_t;
43 
54  Transmitter( const std::string& address,
55  short port, uint64_t tsi, unsigned short mtu,
56  uint32_t rate_limit,
57  boost::asio::io_service& io_service);
58 
62  virtual ~Transmitter();
63 
70  void enable_ipsec( uint32_t spi, const std::string& aes_key);
71 
85  uint16_t send(const std::string& content_location,
86  const std::string& content_type,
87  uint32_t expires,
88  char* data,
89  size_t length);
90 
96  uint64_t seconds_since_epoch();
97 
103  void register_completion_callback(completion_callback_t cb) { _completion_cb = cb; };
104 
105  private:
106  void send_fdt();
107  void send_next_packet();
108  void fdt_send_tick();
109 
110  void file_transmitted(uint32_t toi);
111 
112  void handle_send_to(const boost::system::error_code& error);
113  boost::asio::ip::udp::socket _socket;
114  boost::asio::ip::udp::endpoint _endpoint;
115  boost::asio::io_service& _io_service;
116  boost::asio::deadline_timer _send_timer;
117  boost::asio::deadline_timer _fdt_timer;
118 
119  uint64_t _tsi;
120  uint16_t _mtu;
121 
122  std::unique_ptr<LibFlute::FileDeliveryTable> _fdt;
123  std::map<uint32_t, std::shared_ptr<LibFlute::File>> _files;
124  std::mutex _files_mutex;
125 
126  unsigned _fdt_repeat_interval = 5;
127  uint16_t _toi = 1;
128 
129  uint32_t _max_payload;
130  FecOti _fec_oti;
131 
132  completion_callback_t _completion_cb = nullptr;
133  std::string _mcast_address;
134 
135  uint32_t _rate_limit = 0;
136  };
137 };
FLUTE transmitter class.
Definition: Transmitter.h:34
uint64_t seconds_since_epoch()
Convenience function to get the current timestamp for expiry calculation.
Definition: Transmitter.cpp:71
virtual ~Transmitter()
Default destructor.
std::function< void(uint32_t)> completion_callback_t
Definition of a file transmission completion callback function that can be registered through ::regis...
Definition: Transmitter.h:42
uint16_t send(const std::string &content_location, const std::string &content_type, uint32_t expires, char *data, size_t length)
Transmit a file.
Definition: Transmitter.cpp:93
void enable_ipsec(uint32_t spi, const std::string &aes_key)
Enable IPSEC ESP encryption of FLUTE payloads.
Definition: Transmitter.cpp:60
void register_completion_callback(completion_callback_t cb)
Register a callback for file transmission completion notifications.
Definition: Transmitter.h:103
Transmitter(const std::string &address, short port, uint64_t tsi, unsigned short mtu, uint32_t rate_limit, boost::asio::io_service &io_service)
Default constructor.
Definition: Transmitter.cpp:26
OTI values struct.
Definition: flute_types.h:53