5G-MAG Reference Tools - MBMS Middleware
Public Types | Public Member Functions | Protected Attributes | List of all members
MBMS_RT::ContentStream Class Reference

#include <ContentStream.h>

Collaboration diagram for MBMS_RT::ContentStream:
Collaboration graph

Public Types

enum class  StreamType { Basic , SeamlessSwitching }
 

Public Member Functions

 ContentStream (std::string base, std::string flute_if, boost::asio::io_service &io_service, CacheManagement &cache, DeliveryProtocol protocol, const libconfig::Config &cfg)
 
virtual ~ContentStream ()
 
virtual StreamType stream_type () const
 
virtual std::string stream_type_string () const
 
bool configure_5gbc_delivery_from_sdp (const std::string &sdp)
 
void read_master_manifest (const std::string &manifest)
 
void start ()
 
virtual void flute_file_received (std::shared_ptr< LibFlute::File > file)
 
const std::string & base () const
 
const std::string & playlist_path () const
 
std::string flute_info () const
 
DeliveryProtocol delivery_protocol () const
 
std::string delivery_protocol_string () const
 
const std::string & resolution () const
 
void set_resolution (std::string r)
 
const std::string & codecs () const
 
void set_codecs (std::string c)
 
unsigned long bandwidth () const
 
void set_bandwidth (unsigned long b)
 
double frame_rate () const
 
void set_frame_rate (double f)
 
std::string base_path () const
 
void set_base_path (std::string p)
 

Protected Attributes

const libconfig::Config & _cfg
 
DeliveryProtocol _delivery_protocol
 
std::string _base = ""
 
std::string _base_path
 
std::string _playlist_path
 
std::string _5gbc_stream_iface
 
std::string _5gbc_stream_type = "none"
 
std::string _5gbc_stream_mcast_addr = {}
 
std::string _5gbc_stream_mcast_port = {}
 
unsigned long long _5gbc_stream_flute_tsi = 0
 
std::thread _flute_thread
 
std::unique_ptr< LibFlute::Receiver > _flute_receiver
 
boost::asio::io_service & _io_service
 
CacheManagement_cache
 
std::string _resolution
 
std::string _codecs
 
unsigned long _bandwidth
 
double _frame_rate
 

Detailed Description

Definition at line 29 of file ContentStream.h.

Member Enumeration Documentation

◆ StreamType

Enumerator
Basic 
SeamlessSwitching 

Definition at line 34 of file ContentStream.h.

34  {
35  Basic,
36  SeamlessSwitching
37  };

Constructor & Destructor Documentation

◆ ContentStream()

MBMS_RT::ContentStream::ContentStream ( std::string  base,
std::string  flute_if,
boost::asio::io_service &  io_service,
CacheManagement cache,
DeliveryProtocol  protocol,
const libconfig::Config &  cfg 
)

Definition at line 26 of file ContentStream.cpp.

28  : _5gbc_stream_iface(std::move(flute_if)), _cfg(cfg), _delivery_protocol(protocol), _base(std::move(base)),
29  _io_service(io_service), _cache(cache), _flute_thread{} {
30 }
std::thread _flute_thread
Definition: ContentStream.h:83
CacheManagement & _cache
Definition: ContentStream.h:87
const libconfig::Config & _cfg
Definition: ContentStream.h:70
DeliveryProtocol _delivery_protocol
Definition: ContentStream.h:74
boost::asio::io_service & _io_service
Definition: ContentStream.h:86
const std::string & base() const
Definition: ContentStream.h:47
std::string _5gbc_stream_iface
Definition: ContentStream.h:78
static Config cfg
Global configuration object.
Definition: main.cpp:111

◆ ~ContentStream()

MBMS_RT::ContentStream::~ContentStream ( )
virtual

Definition at line 32 of file ContentStream.cpp.

32  {
33  spdlog::debug("Destroying content stream at base {}", _base);
34  if (_flute_receiver) {
35  _flute_receiver->stop();
36  _flute_thread.join();
37  }
38 }
std::unique_ptr< LibFlute::Receiver > _flute_receiver
Definition: ContentStream.h:84

Member Function Documentation

◆ bandwidth()

unsigned long MBMS_RT::ContentStream::bandwidth ( ) const
inline

Definition at line 63 of file ContentStream.h.

63 { return _bandwidth; }
unsigned long _bandwidth
Definition: ContentStream.h:91

◆ base()

const std::string& MBMS_RT::ContentStream::base ( ) const
inline

Definition at line 47 of file ContentStream.h.

47 { return _base; };

◆ base_path()

std::string MBMS_RT::ContentStream::base_path ( ) const
inline

Definition at line 69 of file ContentStream.h.

69 { return _base_path; }

◆ codecs()

const std::string& MBMS_RT::ContentStream::codecs ( ) const
inline

Definition at line 60 of file ContentStream.h.

60 { return _codecs; }

◆ configure_5gbc_delivery_from_sdp()

auto MBMS_RT::ContentStream::configure_5gbc_delivery_from_sdp ( const std::string &  sdp)

Definition at line 40 of file ContentStream.cpp.

40  {
41  spdlog::debug("ContentStream parsing SDP");
42  std::istringstream iss(sdp);
43  for (std::string line; std::getline(iss, line);) {
44  const std::regex sdp_line_regex("^([a-z])\\=(.+)$");
45  std::smatch match;
46  if (std::regex_match(line, match, sdp_line_regex)) {
47  if (match.size() == 3) {
48  auto field = match[1].str();
49  auto value = match[2].str();
50  spdlog::debug("SDP line {}: {}", field, value);
51 
52  if (field == "c") {
53  const std::regex value_regex("^IN (IP.) ([0-9\\.]+).*$");
54  std::smatch cmatch;
55  if (std::regex_match(value, cmatch, value_regex)) {
56  if (cmatch.size() == 3) {
57  _5gbc_stream_mcast_addr = cmatch[2].str();
58  }
59  }
60  } else if (field == "m") {
61  const std::regex value_regex("^application (.+) (.+)$");
62  std::smatch cmatch;
63  if (std::regex_match(value, cmatch, value_regex)) {
64  if (cmatch.size() == 3) {
65  _5gbc_stream_mcast_port = cmatch[1].str();
66  _5gbc_stream_type = cmatch[2].str();
67  }
68  }
69  const std::regex value_regex2("^application (.+) (.+) (.+)$");
70  if (std::regex_match(value, cmatch, value_regex2)) {
71  if (cmatch.size() == 4) {
72  _5gbc_stream_mcast_port = cmatch[1].str();
73  _5gbc_stream_type = cmatch[2].str();
74  }
75  }
76  } else if (field == "a") {
77  const std::regex value_regex("^flute-tsi:(.+)$");
78  std::smatch cmatch;
79  if (std::regex_match(value, cmatch, value_regex)) {
80  if (cmatch.size() == 2) {
81  _5gbc_stream_flute_tsi = stoul(cmatch[1].str());
82  }
83  }
84  }
85  }
86  }
87  }
88  if (!_5gbc_stream_type.empty() && !_5gbc_stream_mcast_addr.empty() &&
89  !_5gbc_stream_mcast_port.empty()) {
90  spdlog::info("ContentStream SDP parsing complete. Stream type {}, TSI {}, MCast at {}:{}",
92  return true;
93  }
94  return false;
95 }
unsigned long long _5gbc_stream_flute_tsi
Definition: ContentStream.h:82
std::string _5gbc_stream_mcast_port
Definition: ContentStream.h:81
std::string _5gbc_stream_mcast_addr
Definition: ContentStream.h:80
std::string _5gbc_stream_type
Definition: ContentStream.h:79

◆ delivery_protocol()

DeliveryProtocol MBMS_RT::ContentStream::delivery_protocol ( ) const
inline

Definition at line 52 of file ContentStream.h.

52 { return _delivery_protocol; };

◆ delivery_protocol_string()

std::string MBMS_RT::ContentStream::delivery_protocol_string ( ) const
inline

Definition at line 53 of file ContentStream.h.

◆ flute_file_received()

auto MBMS_RT::ContentStream::flute_file_received ( std::shared_ptr< LibFlute::File >  file)
virtual

Definition at line 97 of file ContentStream.cpp.

97  {
98  spdlog::info("ContentStream: {} (TOI {}, MIME type {}) has been received at {}",
99  file->meta().content_location, file->meta().toi, file->meta().content_type, file->received_at());
100  if (file->meta().content_location != "index.m3u8") { // ignore generated manifests
101  std::string content_location = file->meta().content_location;
102  // DASH: Add BaseURl to the content location of the received segments otherwise we do not have a cache match later
104  content_location = _base_path + content_location;
105  }
106 
107  //if this is an MPD also update our internal representation of the MPD
108  if (file->meta().content_location.find(".mpd") != std::string::npos) {
109  _cache.add_item(std::make_shared<CachedFile>(
110  _base_path + "manifest.mpd", file->received_at(), std::move(file))
111  );
112  } else {
113  _cache.add_item(std::make_shared<CachedFile>(
114  content_location, file->received_at(), std::move(file))
115  );
116  }
117 
118  }
119 }
void add_item(std::shared_ptr< CacheItem > item)

◆ flute_info()

auto MBMS_RT::ContentStream::flute_info ( ) const

Definition at line 148 of file ContentStream.cpp.

148  {
149  if (_5gbc_stream_type == "none") {
150  return "n/a";
151  } else {
153  ", TSI " + std::to_string(_5gbc_stream_flute_tsi);
154  }
155 }

◆ frame_rate()

double MBMS_RT::ContentStream::frame_rate ( ) const
inline

Definition at line 66 of file ContentStream.h.

66 { return _frame_rate; }

◆ playlist_path()

const std::string& MBMS_RT::ContentStream::playlist_path ( ) const
inline

Definition at line 48 of file ContentStream.h.

48 { return _playlist_path; };
std::string _playlist_path
Definition: ContentStream.h:77

◆ read_master_manifest()

auto MBMS_RT::ContentStream::read_master_manifest ( const std::string &  manifest)

Definition at line 136 of file ContentStream.cpp.

136  {
138  auto pl = HlsPrimaryPlaylist(manifest, "");
139  if (pl.streams().size() == 1) {
140  auto stream = pl.streams()[0];
141  _playlist_path = stream.uri;
142  } else {
143  spdlog::error("Error: HLS primary playlist for stream contains more than one stream definitions. Ignoring.");
144  }
145  }
146 }

◆ resolution()

const std::string& MBMS_RT::ContentStream::resolution ( ) const
inline

Definition at line 57 of file ContentStream.h.

57 { return _resolution; };

◆ set_bandwidth()

void MBMS_RT::ContentStream::set_bandwidth ( unsigned long  b)
inline

Definition at line 64 of file ContentStream.h.

64 { _bandwidth = b; };

◆ set_base_path()

void MBMS_RT::ContentStream::set_base_path ( std::string  p)
inline

Definition at line 70 of file ContentStream.h.

70 { _base_path = p; };

◆ set_codecs()

void MBMS_RT::ContentStream::set_codecs ( std::string  c)
inline

Definition at line 61 of file ContentStream.h.

61 { _codecs = std::move(c); };

◆ set_frame_rate()

void MBMS_RT::ContentStream::set_frame_rate ( double  f)
inline

Definition at line 67 of file ContentStream.h.

67 { _frame_rate = f; };

◆ set_resolution()

void MBMS_RT::ContentStream::set_resolution ( std::string  r)
inline

Definition at line 58 of file ContentStream.h.

58 { _resolution = std::move(r); };

◆ start()

auto MBMS_RT::ContentStream::start ( )

Definition at line 121 of file ContentStream.cpp.

121  {
122  spdlog::info("ContentStream starting");
123  if (_5gbc_stream_type == "FLUTE/UDP") {
124  spdlog::info("Starting FLUTE receiver on {}:{} for TSI {}", _5gbc_stream_mcast_addr, _5gbc_stream_mcast_port,
126  _flute_thread = std::thread{[&]() {
127  _flute_receiver = std::make_unique<LibFlute::Receiver>(_5gbc_stream_iface, _5gbc_stream_mcast_addr,
128  atoi(_5gbc_stream_mcast_port.c_str()),
130  _flute_receiver->register_completion_callback(
131  boost::bind(&ContentStream::flute_file_received, this, _1)); //NOLINT
132  }};
133  }
134 };
virtual void flute_file_received(std::shared_ptr< LibFlute::File > file)

◆ stream_type()

virtual StreamType MBMS_RT::ContentStream::stream_type ( ) const
inlinevirtual

Definition at line 38 of file ContentStream.h.

◆ stream_type_string()

virtual std::string MBMS_RT::ContentStream::stream_type_string ( ) const
inlinevirtual

Definition at line 39 of file ContentStream.h.

39 { return "Basic"; };

Member Data Documentation

◆ _5gbc_stream_flute_tsi

unsigned long long MBMS_RT::ContentStream::_5gbc_stream_flute_tsi = 0
protected

Definition at line 82 of file ContentStream.h.

◆ _5gbc_stream_iface

std::string MBMS_RT::ContentStream::_5gbc_stream_iface
protected

Definition at line 78 of file ContentStream.h.

◆ _5gbc_stream_mcast_addr

std::string MBMS_RT::ContentStream::_5gbc_stream_mcast_addr = {}
protected

Definition at line 80 of file ContentStream.h.

◆ _5gbc_stream_mcast_port

std::string MBMS_RT::ContentStream::_5gbc_stream_mcast_port = {}
protected

Definition at line 81 of file ContentStream.h.

◆ _5gbc_stream_type

std::string MBMS_RT::ContentStream::_5gbc_stream_type = "none"
protected

Definition at line 79 of file ContentStream.h.

◆ _bandwidth

unsigned long MBMS_RT::ContentStream::_bandwidth
protected

Definition at line 91 of file ContentStream.h.

◆ _base

std::string MBMS_RT::ContentStream::_base = ""
protected

Definition at line 75 of file ContentStream.h.

◆ _base_path

std::string MBMS_RT::ContentStream::_base_path
protected

Definition at line 76 of file ContentStream.h.

◆ _cache

CacheManagement& MBMS_RT::ContentStream::_cache
protected

Definition at line 87 of file ContentStream.h.

◆ _cfg

const libconfig::Config& MBMS_RT::ContentStream::_cfg
protected

Definition at line 73 of file ContentStream.h.

◆ _codecs

std::string MBMS_RT::ContentStream::_codecs
protected

Definition at line 90 of file ContentStream.h.

◆ _delivery_protocol

DeliveryProtocol MBMS_RT::ContentStream::_delivery_protocol
protected

Definition at line 74 of file ContentStream.h.

◆ _flute_receiver

std::unique_ptr<LibFlute::Receiver> MBMS_RT::ContentStream::_flute_receiver
protected

Definition at line 84 of file ContentStream.h.

◆ _flute_thread

std::thread MBMS_RT::ContentStream::_flute_thread
protected

Definition at line 83 of file ContentStream.h.

◆ _frame_rate

double MBMS_RT::ContentStream::_frame_rate
protected

Definition at line 92 of file ContentStream.h.

◆ _io_service

boost::asio::io_service& MBMS_RT::ContentStream::_io_service
protected

Definition at line 86 of file ContentStream.h.

◆ _playlist_path

std::string MBMS_RT::ContentStream::_playlist_path
protected

Definition at line 77 of file ContentStream.h.

◆ _resolution

std::string MBMS_RT::ContentStream::_resolution
protected

Definition at line 89 of file ContentStream.h.


The documentation for this class was generated from the following files: