5G-MAG Reference Tools - MBMS Middleware
Classes | Public Member Functions | Private Attributes | List of all members
MBMS_RT::HlsMediaPlaylist Class Reference

#include <HlsMediaPlaylist.h>

Collaboration diagram for MBMS_RT::HlsMediaPlaylist:
Collaboration graph

Classes

struct  Segment
 

Public Member Functions

 HlsMediaPlaylist (const std::string &content)
 
 HlsMediaPlaylist ()=default
 
 ~HlsMediaPlaylist ()=default
 
const std::vector< Segment > & segments () const
 
void add_segment (Segment segment)
 
std::string to_string () const
 
void set_target_duration (int duration)
 
int target_duration () const
 

Private Attributes

int _version = -1
 
int _targetduration
 
std::vector< Segment_segments = {}
 

Detailed Description

Definition at line 24 of file HlsMediaPlaylist.h.

Constructor & Destructor Documentation

◆ HlsMediaPlaylist() [1/2]

MBMS_RT::HlsMediaPlaylist::HlsMediaPlaylist ( const std::string &  content)

Definition at line 24 of file HlsMediaPlaylist.cpp.

25 {
26  spdlog::debug("Parsing HLS media playlist: {}", content);
27 
28  std::istringstream iss(content);
29  int idx = 0;
30  int seq_nr = 0;
31  double extinf = -1;
32  for (std::string line; std::getline(iss, line); idx++ )
33  {
34  boost::algorithm::trim(line);
35 
36  if (idx==0) {
37  if ( line != "#EXTM3U") {
38  throw("HLS playlist parsing failed: first line is not #EXTM3U");
39  } else {
40  continue;
41  }
42  }
43 
44  size_t cpos = line.rfind(':');
45 
46  if (line.rfind("#EXT-X-VERSION", 0) == 0) {
47  if (_version != -1) {
48  throw("HLS playlist parsing failed: duplicate #EXT-X-VERSION");
49  }
50  if (cpos != std::string::npos) {
51  _version = atoi(line.substr(cpos+1).c_str());
52  }
53  } else if (line.rfind("#EXT-X-TARGETDURATION", 0) == 0) {
54  if (cpos != std::string::npos) {
55  _targetduration = atoi(line.substr(cpos+1).c_str());
56  }
57  } else if (line.rfind("#EXT-X-MEDIA-SEQUENCE", 0) == 0) {
58  if (cpos != std::string::npos) {
59  seq_nr = atoi(line.substr(cpos+1).c_str());
60  }
61  } else if (line.rfind("#EXTINF", 0) == 0) {
62  if (cpos != std::string::npos) {
63  extinf = atof(line.substr(cpos+1).c_str());
64  }
65  } else if (line.rfind('#', 0) == 0) {
66  spdlog::debug("HLS playlist parser ignoring unhandled line {}", line);
67  } else if (line.size() > 0) {
68  _segments.push_back({line, seq_nr++, extinf});
69  }
70  }
71 }
std::vector< Segment > _segments

◆ HlsMediaPlaylist() [2/2]

MBMS_RT::HlsMediaPlaylist::HlsMediaPlaylist ( )
default

◆ ~HlsMediaPlaylist()

MBMS_RT::HlsMediaPlaylist::~HlsMediaPlaylist ( )
default

Member Function Documentation

◆ add_segment()

void MBMS_RT::HlsMediaPlaylist::add_segment ( Segment  segment)
inline

Definition at line 36 of file HlsMediaPlaylist.h.

36 { _segments.push_back(std::move(segment)); };

◆ segments()

const std::vector<Segment>& MBMS_RT::HlsMediaPlaylist::segments ( ) const
inline

Definition at line 35 of file HlsMediaPlaylist.h.

35 { return _segments; };

◆ set_target_duration()

void MBMS_RT::HlsMediaPlaylist::set_target_duration ( int  duration)
inline

Definition at line 40 of file HlsMediaPlaylist.h.

40 { _targetduration = duration; };

◆ target_duration()

int MBMS_RT::HlsMediaPlaylist::target_duration ( ) const
inline

Definition at line 41 of file HlsMediaPlaylist.h.

41 { return _targetduration; };

◆ to_string()

auto MBMS_RT::HlsMediaPlaylist::to_string ( ) const

Definition at line 74 of file HlsMediaPlaylist.cpp.

75 {
76  std::stringstream pl;
77 
78  pl << "#EXTM3U" << std::endl;
79  pl << "#EXT-X-VERSION:3" << std::endl;
80 
81  if (_segments.size() > 0) {
82  pl << "#EXT-X-TARGETDURATION:" << _targetduration << std::endl;
83  pl << "#EXT-X-MEDIA-SEQUENCE:" << _segments[0].seq << std::endl;
84  }
85  for (const auto& seg : _segments) {
86  pl << "#EXTINF:" << seg.extinf << std::endl;
87  pl << "/" << seg.uri << std::endl;
88  }
89  return std::move(pl.str());
90 }

Member Data Documentation

◆ _segments

std::vector<Segment> MBMS_RT::HlsMediaPlaylist::_segments = {}
private

Definition at line 46 of file HlsMediaPlaylist.h.

◆ _targetduration

int MBMS_RT::HlsMediaPlaylist::_targetduration
private

Definition at line 45 of file HlsMediaPlaylist.h.

◆ _version

int MBMS_RT::HlsMediaPlaylist::_version = -1
private

Definition at line 44 of file HlsMediaPlaylist.h.


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