5G-MAG Reference Tools - MBMS Middleware
ServiceAnnouncement.h
Go to the documentation of this file.
1 // 5G-MAG Reference Tools
2 // MBMS Middleware Process
3 //
4 // Copyright (C) 2021 Klaus Kühnhammer (Österreichische Rundfunksender GmbH & Co KG)
5 //
6 // Licensed under the License terms and conditions for use, reproduction, and
7 // distribution of 5G-MAG software (the “License”). You may not use this file
8 // except in compliance with the License. You may obtain a copy of the License at
9 // https://www.5g-mag.com/reference-tools. Unless required by applicable law or
10 // agreed to in writing, software distributed under the License is distributed on
11 // an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12 // or implied.
13 //
14 // See the License for the specific language governing permissions and limitations
15 // under the License.
16 //
17 
18 #pragma once
19 
20 #include <string>
21 #include <thread>
22 #include <libconfig.h++>
23 #include <tinyxml2.h>
24 #include "cpprest/http_client.h"
25 #include "File.h"
26 #include "Receiver.h"
27 #include "Service.h"
28 #include "CacheManagement.h"
29 #include "Constants.h"
30 
31 namespace MBMS_RT {
33  public:
34  typedef std::function<std::shared_ptr<Service>(const std::string &service_id)> get_service_callback_t;
35  typedef std::function<void(const std::string &service_id, std::shared_ptr<Service>)> set_service_callback_t;
36 
37  ServiceAnnouncement(const libconfig::Config &cfg, std::string tmgi, const std::string &mcast,
38  unsigned long long tsi,
39  std::string iface, boost::asio::io_service &io_service, CacheManagement &cache,
40  bool seamless_switching,
41  get_service_callback_t get_service, set_service_callback_t set_service);
42 
43  virtual ~ServiceAnnouncement();
44 
45  struct Item {
46  std::string content_type;
47  std::string uri;
48  time_t valid_from;
49  time_t valid_until;
50  unsigned version;
51  std::string content;
52  };
53 
54  const std::vector<Item> &items() const { return _items; };
55 
56  const std::string &content() const { return _raw_content; };
57 
58  uint32_t toi() const { return _toi; };
59 
60  void parse_bootstrap(const std::string &str);
61 
62  void start_flute_receiver(const std::string &mcast_address);
63 
64  private:
65 
68 
69  bool _seamless = false;
70 
71  std::vector<Item> _items;
72 
73  const libconfig::Config &_cfg;
74 
75  bool _bootstrapped = false;
76 
77  uint32_t _toi = {};
78  std::string _raw_content;
79  std::string _iface;
80  std::string _tmgi;
81  std::string _mcast_addr;
82  std::string _mcast_port;
83  std::string _base_path;
84  unsigned long long _tsi = 0;
85  std::thread _flute_thread;
86  std::unique_ptr<LibFlute::Receiver> _flute_receiver;
87 
88  boost::asio::io_service &_io_service;
90 
91  void _addServiceAnnouncementItems(const std::string &str);
92 
93  void _handleMbmsEnvelope(const Item &item);
94 
95  void _handleMbmbsUserServiceDescriptionBundle(const Item &item, const std::string &bootstrap_format);
96 
97  std::tuple<std::shared_ptr<MBMS_RT::Service>, bool>
98  _registerService(tinyxml2::XMLElement *usd, const std::string &service_id);
99 
100  void _handleAppService(tinyxml2::XMLElement *app_service, const std::shared_ptr<Service> &service);
101 
102  bool _setupBroadcastDelivery(tinyxml2::XMLElement *usd, std::string base, std::shared_ptr<ContentStream> cs);
103 
104  void
105  _setupByAlternativeContentElement(tinyxml2::XMLElement *app_service,
106  const std::shared_ptr<MBMS_RT::Service> &service,
107  tinyxml2::XMLElement *usd);
108 
109  void
110  _setupBy5GMagConfig(tinyxml2::XMLElement *app_service,
111  const std::shared_ptr<MBMS_RT::Service> &service,
112  tinyxml2::XMLElement *usd);
113 
114  void
115  _setupBy5GMagLegacyFormat(tinyxml2::XMLElement *app_service,
116  const std::shared_ptr<MBMS_RT::Service> &service,
117  tinyxml2::XMLElement *usd);
118  };
119 }
void _handleMbmsEnvelope(const Item &item)
Parses the MBMS envelope.
void _addServiceAnnouncementItems(const std::string &str)
Iterates through the service announcement file and adds the different sections/items to the the list ...
void _handleMbmbsUserServiceDescriptionBundle(const Item &item, const std::string &bootstrap_format)
Parses the MBMS USD.
get_service_callback_t _get_service
const std::string & content() const
void _handleAppService(tinyxml2::XMLElement *app_service, const std::shared_ptr< Service > &service)
Parse the appService element Spec: Presence of the r12:appService child element of userServiceDescrip...
std::unique_ptr< LibFlute::Receiver > _flute_receiver
void _setupBy5GMagConfig(tinyxml2::XMLElement *app_service, const std::shared_ptr< MBMS_RT::Service > &service, tinyxml2::XMLElement *usd)
void _setupBy5GMagLegacyFormat(tinyxml2::XMLElement *app_service, const std::shared_ptr< MBMS_RT::Service > &service, tinyxml2::XMLElement *usd)
Setup according to the format that was used for the first 5G-MAG sample recordings.
std::function< std::shared_ptr< Service >const std::string &service_id)> get_service_callback_t
void start_flute_receiver(const std::string &mcast_address)
Starts the FLUTE receiver at the specified multicast address.
bool _setupBroadcastDelivery(tinyxml2::XMLElement *usd, std::string base, std::shared_ptr< ContentStream > cs)
std::tuple< std::shared_ptr< MBMS_RT::Service >, bool > _registerService(tinyxml2::XMLElement *usd, const std::string &service_id)
Creates a new service or finds an existing service for the specified service id.
boost::asio::io_service & _io_service
set_service_callback_t _set_service
std::function< void(const std::string &service_id, std::shared_ptr< Service >)> set_service_callback_t
const libconfig::Config & _cfg
const std::vector< Item > & items() const
void parse_bootstrap(const std::string &str)
Parse the service announcement/bootstrap file.
void _setupByAlternativeContentElement(tinyxml2::XMLElement *app_service, const std::shared_ptr< MBMS_RT::Service > &service, tinyxml2::XMLElement *usd)
Setup according to original SA format with an alternativeContentElement required to indicate that the...
ServiceAnnouncement(const libconfig::Config &cfg, std::string tmgi, const std::string &mcast, unsigned long long tsi, std::string iface, boost::asio::io_service &io_service, CacheManagement &cache, bool seamless_switching, get_service_callback_t get_service, set_service_callback_t set_service)
static Config cfg
Global configuration object.
Definition: main.cpp:111